问题描述
C++:GPSSUPPORT_APIint__stdcallress(unsignedchar*compr,unsignedlongcomprLen,unsignedchar**uncompr,unsignedlong*uncomprLen);C#:publicstaticexternintZlibUncompress(refbyte[]compr,longcomprLen,refbyte[]uncompr,reflonguncomprLen);调用:privatebyte[]Keys={0x78,0xDA,0x63,0x60,0x60,0x6C,0x60,0x6A,0x63,0x64,0x60,0x16,0x06,0x00,0x06,0x59,0x01,0x21};byte[]b=newbyte[255];longblen=a.Length;intErr=XWAPI.ZlibUncompress(refa,(long)a.Length,refb,refblen);提示:尝试读取或写入受保护的内存。这通常指示其他内存已损坏"如何处理,谢谢.尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
解决方案
解决方案二:
C++的代码:GPSSUPPORT_APIint__stdcallZlibUncompress(unsignedchar*compr,unsignedlongcomprLen,unsignedchar**uncompr,unsignedlong*uncomprLen);
解决方案三:
C++代码写错了.是这样的:GPSSUPPORT_APIint__stdcallZlibUncompress(unsignedchar*compr,unsignedlongcomprLen,unsignedchar**uncompr,unsignedlong*uncomprLen);
解决方案四:
看不出来,不过char*一般对应C#里的string或者StringBuilder
解决方案五:
先用C写个测试程序看看,
解决方案六:
引用4楼wodegege10的回复:
先用C写个测试程序看看,
.
解决方案七:
引用2楼chinakgsoft的回复:
C++代码写错了.是这样的:GPSSUPPORT_APIint__stdcallZlibUncompress(unsignedchar*compr,unsignedlongcomprLen,unsignedchar**uncompr,unsignedlong*uncomprLen);
[DllImport("xx.dll")]publicstaticexternintZlibUncompress(byte[]compr,uintcomprLen,refbyte[]uncompr,refuintuncomprLen);
解决方案八:
[DllImport("xx.dll")]publicstaticexternintZlibUncompress(byte[]compr,uintcomprLen,refbyte[]uncompr,refuintuncomprLen);privatebyte[]Keys={0x78,0xDA,0x63,0x60,0x60,0x6C,0x60,0x6A,0x63,0x64,0x60,0x16,0x06,0x00,0x06,0x59,0x01,0x21};uintblen=0;uintalen=Convert.ToUInt32(Keys.Length);byte[]buffer=newbyte[128];intErr=XWAPI.ZlibUncompress(Keys,alen,refbuffer,refblen);我这样写了.可是blen是对的.但buffer的没值,值不对.请上楼的朋友帮我看看.谢谢.
解决方案九:
LZ的c++函数是否写错了?我在网上查了一下LZ用的是zlib.dll来压缩解压缩吧貌似c++的函数原型不是这样的你再仔细检查检查压缩解压缩的别写反了..
解决方案十:
[DllImport("xx.dll")]publicstaticexternintZlibUncompress(byte[]compr,uintcomprLen,refbyte[]uncompr,refuintuncomprLen);
解决方案十一:
[DllImport("xx.dll")]publicstaticexternintZlibUncompress(byte[]compr,uintcomprLen,refbyte[]uncompr,refuintuncomprLen);