You have a structure that takes a byte array
byte[]
however, the size of that array depends on the image you are submitting (widthxheight)
So... how do you do
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ???)]
public Byte[] ImageData;
Is the sizeconst a MUST HAVE when working with byte arrays being passed from C# to C dlls?
You need to change the marshalling type. SizeConst is required if you're marshalling as ByValArray, but not with other types. For details, look at the UnmanagedType enum.
My suspicion is that you want to marshall as a C pointer to the array:
[MarshalAs(UnmanagedType.LPArray)]
This will cause it to marshall through to a standard C array (BYTE*), so only a pointer is passed through. Doing this allows you to pass any sized array. Typically, you'll also want to pass through the array size as another parameter (or image width/height/bpp, which provides the same info), since there's no way in C/C++ to tell that easily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With