- In my c-code, I have a structure that contains many unknown arrays in an unmanaged dll (c-code)
- I need the data of one instance of this structure, bound to C # , which I will later send back to unmanaged code c
- I do not need to manipulate this data when it gets into csharp, just hold it / keep it for a while (so that it can remain in an array of bytes).
-I donโt want to use the keyword โunsafeโ, because this is a large project, and this is just one small part, and I do not want to compile such files.
I tried marshaling it as lpArray and everything looks fine, but when I look at the contents after returning to csharp, it is always empty. This type of marshaling style worked for me for dynamic arrays of various types, but not for structure.
A search on the Internet is a workpiece and much more complex scripts than my own, but if anyone saw such a link, send it here, I would be very grateful!
Thanks.
- update here more or less the structure of my code:
FROM#:
[DllImport("mydll.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] private static extern int W_Thread_Connect_NET( [MarshalAs(UnmanagedType.LPStr, SizeConst = 100)] string IPAddress, int DevicePort, [MarshalAs(UnmanagedType.LPArray)] byte[] connectionHandle );
from:
typedef struct myStructDef{ char* myArray1, char* myArray2, int myInt1, ... } mystrucObj, *pMystrucObj;