C++:GPSSUPPORT_API int __stdcall  ress(unsigned char *compr, unsigned long comprLen, unsigned char **uncompr, unsigned long *uncomprLen);
C#:
public static extern int ZlibUncompress(ref byte[] compr, long comprLen, ref byte[] uncompr, ref long uncomprLen);
调用:
private byte[] Keys = { 0x78, 0xDA, 0x63, 0x60, 0x60, 0x6C, 0x60, 0x6A, 0x63, 0x64, 0x60, 0x16, 0x06, 0x00, 0x06, 0x59, 0x01, 0x21 };
            byte[] b=new byte[255];
            long blen=a.Length;
            int Err = XWAPI.ZlibUncompress(ref a, (long)a.Length, ref b, ref blen);
提示:尝试读取或写入受保护的内存。这通常指示其他内存已损坏"
如何处理,谢谢.
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

解决方案 »

  1.   

    C++的代码:GPSSUPPORT_API int __stdcall  ZlibUncompress(unsigned char *compr, unsigned long comprLen, unsigned char **uncompr, unsigned long *uncomprLen);
      

  2.   

    C++代码写错了.是这样的:GPSSUPPORT_API int __stdcall  ZlibUncompress(unsigned char *compr, unsigned long comprLen, unsigned char **uncompr, unsigned long *uncomprLen);
      

  3.   

    看不出来,不过char*一般对应C#里的string或者StringBuilder
      

  4.   

    [DllImport("xx.dll")]
    public static extern int ZlibUncompress(byte[] compr,uint comprLen,ref byte[] uncompr,ref uint uncomprLen);
      

  5.   

    [DllImport("xx.dll")]
    public static extern int ZlibUncompress(byte[] compr,uint comprLen,ref byte[] uncompr,ref uint uncomprLen);
                private byte[] Keys = { 0x78, 0xDA, 0x63, 0x60, 0x60, 0x6C, 0x60, 0x6A, 0x63, 0x64, 0x60, 0x16, 0x06, 0x00, 0x06, 0x59, 0x01, 0x21 };            uint blen=0;
                uint alen = Convert.ToUInt32(Keys.Length);
                byte[] buffer = new byte[128];   
                int Err = XWAPI.ZlibUncompress(Keys, alen, ref buffer, ref blen);我这样写了.可是blen是对的.但buffer的没值,值不对.请上楼的朋友帮我看看.谢谢.
      

  6.   

    LZ的c++函数是否写错了?
    我在网上查了一下 LZ用的是zlib.dll来压缩解压缩吧 貌似c++的函数原型不是这样的 你再仔细检查检查 压缩 解压缩的别写反了..
      

  7.   

    [DllImport("xx.dll")]
    public static extern int ZlibUncompress(byte[] compr,uint comprLen,ref byte[] uncompr,ref uint uncomprLen);
      

  8.   

    [DllImport("xx.dll")]
    public static extern int ZlibUncompress(byte[] compr,uint comprLen,ref byte[] uncompr,ref uint uncomprLen);