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:

Code:
typedef struct test_struct{
    uint8_t Array[100];
} test_struct;
and the corresponding managed version

Code:
[StructLayout(LayoutKind::Sequential)]
ref struct test_struct {
      [MarshalAs(UnmanagedType::ByValArray,SizeConst=100)]
      static array<unsigned char>^ Array;     
};
This is the prototype for the unmanaged function

Code:
int function_test(test_struct * test)
and the call from managed code

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;
        }
At the time of the call, the struct indicates:
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.