Hi All,
I have an unmanaged C function that takes in a struct that contains a fixed length array. I have declared the array in both C and C++/CLI so the type conversion should be handled implicitly however I must have a mistake somewhere.
When I debug, the array that is passed into the unmanaged code is offset by 16 bytes (seemingly the header information for the array). Data can be returned to the managed code so long as the offset is used.
Here is a cut down version of the unmanaged struct:
and the corresponding managed versionCode:typedef struct test_struct{ uint8_t Array[100]; } test_struct;
This is the prototype for the unmanaged functionCode:[StructLayout(LayoutKind::Sequential)] ref struct test_struct { [MarshalAs(UnmanagedType::ByValArray,SizeConst=100)] static array<unsigned char>^ Array; };
and the call from managed codeCode:int function_test(test_struct * test)
At the time of the call, the struct indicates:Code:int Test (test_struct^% pTest) { test_struct test; test.Array = gcnew array<unsigned char>(100); test.Array[0] = 2; int result = function_test (test); pTest = %test; return result; }
Array[0] = 2
Array[1] = 0
Array[2] = 0
etc
Then inside the call the arguement changes to
Array[0 to 15] = Random data
Array[16] = 2
Array[17] = 0
Array[18] = 0
etc
Thanks in advance.


Reply With Quote


Bookmarks