Good day.
You must pass a pointer to the IntPtr structure lpCmdData to the external library:
[DllImport("xxx.dll", SetLastError = true)] public static extern IntPtr Start(IntPtr hService, uint dwCommand, IntPtr lpCmdData, uint dwTimeOut, ref _wfs_result lppResult); The code for the structure itself is as follows:
[StructLayout(LayoutKind.Explicit)] public struct my_struct { [FieldOffset(0)] public ushort a; [FieldOffset(2)] public ushort b; [FieldOffset(4)] public uint c; [FieldOffset(8)] public bool d; [FieldOffset(9)] public IntPtr e; }; Getting a pointer to the structure is done through Marshal.StructureToPtr:
int iSizeOfStruct = Marshal.SizeOf(typeof(my_struct)); IntPtr ptrDispense = Marshal.AllocHGlobal(iSizeOfStruct); Marshal.StructureToPtr(Struct1, ptrDispense, true); I get the pointer when I pass it to the DLL, then I get an error that the pointer is not correct .. After two days I come to the conclusion that the resulting structure address is available only within .NET, therefore it is not a physical memory address, but a logical address. Is it possible to get a real physical memory address that will be available outside the application on .NET? Or can you create a structure outside a protected area?
PS picking the code, I noticed the following, when the DLL returns a memory pointer to me, then it consists of 10 numbers - example 1255246569. When a pointer is received in .NET, it consists of 7 numbers - 1542952