title: How to pass a buffer of binary data from C to C# with pinvoke
body: <p>I have a DLL coded in C that has functions that output image data as unsigned char *, convert between different image formats and so on. I have a client who wants to make use of this from C#. I guess that the apppropriate data type on the C# side would be byte [].</p>
  
  <p>I thought that PInvoke would help, but I cant find the appropriate technique to marshall this "binary data" to C# (whose variable length is stored in a separate variable). All the marshalling examples I have seen concern null terminated strings and an image array does not stop at an ascii null.</p>
  
  <p>I have seen that I might alternatively consider passing the pointer to the data via an IntPtr but it
  looks like this would involve unsafe code on the C# side.</p>