I have a C++ Header File that gives me access to two functions that, after cutting stuff that is not necessary, are this:
extern __declspec (dllimport) bool __cdecl GetBinary(unsigned short* _allocatedBufferSizeBufferLength, char* _receiveBuffer);
The _data and _receiveBuffer parameters are supposed to be binary information, not the strings as char* would initially suggest.
The reference C++ implementation I have would use the functions like this:
char output;
unsigned short allocatedBufferLength = 1;
GetBinary(&allocatedBufferLength,&output);
My Import Declaration for these two right now looks like this:
[DllImport( "MyDriver.dll", EntryPoint = "GetBinary", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl )]
public static extern bool GetBinary( out ushort allocatedBufferSizeBufferLength, StringBuilder receiveBuffer );
With this in mind, what I try to get as a result are byte[] binary arrays. This works well in most cases. However, I have byte arrays with "0" bytes right in the middle. With the StringBuilder this will result in me only getting the first part of the array. How would I be able to reliably get the entire binary array/blob?
Edit: This is how I use it in my C# Method, normally I can extract the binary data from the string inside the StringBuilder:
StringBuilder outVar = new StringBuilder( 30 );
allocatedBufferLength = (ushort)(outVar.Length - 1);
UnsafeNativeMethods.GetBinary( out allocatedBufferLength, outVar );