I have an already developed C# application, that needs to pass a pointer to
an array of bytes (of size 50), to another already developed C++ application
hosted in a DLL. My array of bytes are hosted in an unsafe static class to
force the C# garbage collector not to move it around, as the C++ application
will be responsible to update the array during runtime. My structure is
defined as follows:
[StructLayout(LayoutKind.Sequential)]
public struct DATA
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst=50)]
public statis byte[] myArray;
}
I attempt to pass the reference of the array to the C++ application in the
following manner:
fixed (byte *address = &MyStaticClass.DATA.myArray[0])
{
MyApplication.SetArrayReference(address);
}
Now, when I attempt to pass a reference to this array to the C++ application
(see insert above), the following exception occurs:
System.NullReferenceException >> "Object reference not set to an instance of
an object.". Any idea what I am doing wrong, and how this can be solved?
Regards
Nico Gerber