The following code works without problems. It is very similar to yours:
C ++:
extern "C" __declspec(dllexport) void TestFunction(char* inp_buff, unsigned short* inp_len, char* buffer_decomp, unsigned *output_len, unsigned short* errorCode) {
FROM#:
using System; using System.Runtime.InteropServices; class Program { [DllImport("TEST.DLL")] public static extern void TestFunction(byte[] inp_buff, ref ushort inp_len, byte[] out_buff, ref int out_len, ref ushort errorCode); static void Main(string[] args) {
Give it a try. I looked at the open parts of the library that you are using. Here is a direct excerpt from the lzo_decomp function:
in = lzo_malloc(IN_LEN); out = lzo_malloc(OUT_LEN); wrkmem = lzo_malloc(LZO1Z_999_MEM_COMPRESS); if (in == NULL || out == NULL || wrkmem == NULL) { printf("out of memory\n"); } in_len = IN_LEN; lzo_memset(in,0,in_len ); lzo_memset ( out, 0, OUT_LEN ); memcpy ( out, &input_buffer, inp_buff_len); lzo_free(wrkmem); lzo_free(out); lzo_free(in); r = lzo1z_decompress(out,*inp_len,in,&out_len,NULL );
For peace of mind: "in" and "out" are not function arguments for input and output buffers, but temporary pointers. What can you see (besides bad formatted code)? Only two lzo1z_decompress buffers are called: "in" and "out". And these two buffers are freed before the call. I am not surprised that there is a violation of access rights. I can only emphasize the advice of nobugz: Contact the author.
source share