You should be able to pass the unsigned char* parameter in as a byte[] and standard P/Invoke marshaller should handle that. You will have to marshal the output unsigned char* yourself, but that should just be a call to Marshall.Copy(). See below for an example of what I think will work.
Two big questions:
- How does the caller know the size of data stored in the return unsigned char* buffer?
- How is the memory allocated for the return unsigned char* buffer? Do you have to free it and how will you free it from C# if you need to?
Sample:
[DllImport("Name.dll")]
private static extern IntPtr Compress([MarshalAs(UnmanagedType.LPArray)]byte[] buffer, int size);
[DllImport("Name.dll")]
private static extern IntPtr Decompress([MarshalAs(UnmanagedType.LPArray)]byte[] buffer, int size);
public static byte[] Compress(byte[] buffer) {
IntPtr output = Compress(buffer, buffer.Length);
/* Does output need to be freed? */
byte[] outputBuffer = new byte[/*some size?*/];
Marshal.Copy(output, outputBuffer, 0, outputBuffer.Length);
return outputBuffer;
}
public static byte[] Decompress(byte[] buffer) {
IntPtr output = Decompress(buffer, buffer.Length);
/* Does output need to be freed? */
byte[] outputBuffer = new byte[/*some size?*/];
Marshal.Copy(output, outputBuffer, 0, outputBuffer.Length);
return outputBuffer;
}