I am developing c.dll, which should be accessed from a C # program. Ideally, a .dll should get any structure defined in C # and do something with it. So, initially the type and size of the structure are unknown for C dll. I was able to pass the structure through the C extern function, and it was submitted so that it could be received in order, but is there any way to find out the size and characteristics of this reception structure? is there any way to iterate over its members?
This is the C function defined for dll
extern int __cdecl testCSharp(mystruct * Test){
}
This is C # code
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)] unsafe public struct myStruct{ [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 100)] public string value1; [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 100)] public string value2; [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 100)] public string value3; [MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 100)] public string value4; }; [DllImport("SMKcomUploadDLL.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int testCSharp(ref myStruct message); static void Main() { int result; myStruct message = new myStruct(); message.value1 = "Some randome string"; message.value2 = "0"; message.value3 = "olkujhikvb"; message.value4 = "isabedfbfmlk"; result = testCSharp(ref message); }
All types are String in C #, and it is assumed that they remain so, so I only know about the structure that will be passed.
Any idea?
Thank you in advance
source share