C# 调用C++的dll,提示"尝试读取或写入受保护的内存。这通常指示其他内存已损坏"

问题描述

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);

时间: 2024-08-02 05:10:05

C# 调用C++的dll,提示"尝试读取或写入受保护的内存。这通常指示其他内存已损坏"的相关文章

c#调用c++dll报错:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 c++原型函数boolDetBelt(constchar*chImgFile,doubledStrictDegree=1.0,XSCRECTroiRect=XSCRECT(),constchar*dstFile=NULL);structXSCRECT{intx;inty;intheight;intwidth;XSCRECT(){x=0;y=0;height=0;width=0;}};声明c#代码[StructLayoutAttribute(LayoutKind.Sequential)]

求助,C#调用C++dll时提示:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 C++dll的头文件接口描述如下:#pragmapack(push,1)typedefstructXCtrlStatus{XCtrlStatus(unsignedlongV=0){*reinterpret_cast<unsignedlong*>(this)=V;}unsignedcharERR:1;unsignedcharAUTO:1;unsignedcharRUN:2;unsignedcharDIR:2;unsignedchar:1;unsignedchar:1;unsignedc

C#调用其他语言DLL库,提示尝试读取或写入受保护的内存。这通常指示其他内存已损坏

问题描述 C#调用其他语言DLL库,提示尝试读取或写入受保护的内存.这通常指示其他内存已损坏代码如下==========================================DLL函数int__stdcallActionReceived(constchar*devId,constint*windowId,constchar*cmd,char*data)==========================================C#调用[DllImport(@"Caller.dl

dll c#-c#调用c++的dll出现尝试读取或写入受保护的内存问题

问题描述 c#调用c++的dll出现尝试读取或写入受保护的内存问题 使用c#调用c++的一个dll.c++的接口函数为: extern "C" __declspec(dllexport)bool __stdcall CreateDetmObject(IDetManager **ppDetManager); 参数IDetManager为一个结构体: struct IDetManager { virtual void __stdcall SetListener(HWND hWnd) = 0

c#调用dll 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 调用一个自己写的c++的dll,结果出现问题提示如下:"System.AccessViolationException"类型的未经处理的异常出现在BidingSystem_Client.exe中.其他信息:尝试读取或写入受保护的内存.这通常指示其他内存已损坏.--------------------------------------------c#[DllImport("PEKS.dll",CharSet=CharSet.Ansi,CallingConv

c++-C# 调用C++ dll是出现这样的错误“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 C# 调用C++ dll是出现这样的错误"尝试读取或写入受保护的内存.这通常指示其他内存已损坏. 调试时是这样的: SDK上是这样说明的: 我调用这个dll时是这样的: 困扰了很久,希望有大神来看一看,感激不敬 解决方案 C#尝试读取或写入受保护的内存.这通常指示其他内存已损坏.C# 尝试读取或写入受保护的内存 .这通常指示其他内存已损坏.C#尝试读取或写入受保护的内存.这通常指示其他内存已损坏. 解决方案二: 先看是不是你的参数有问题,然后就是数据对不对 解决方案三: 是不是重复调用

c#调用delphi编写的dll文件报错,尝试读取或写入受保护的内存

问题描述 c#调用delphi编写的dll文件报错,尝试读取或写入受保护的内存 delphi函数原型 Procedure invoke(params :PChar; result : PChar) ; 解决方案 把这个delphi的原型改一下,改为 Function Pchar invoke(params :PChar) ; 再试试 解决方案二: Function invoke(params: PAnsiChar): PAnsiChar ;

C# 调用C++的DLL文件出现问题。尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

问题描述 我用C#开发一个项目,需要饮用C++的DLL,但是调用其中的方法是有几个函数正常,有一些方法总是报错.错误为:"尝试读取或写入受保护的内存.这通常指示其他内存已损坏."哪位大神可以帮我看看.这是DLL中的方法:typedefstructehInformation{std::stringehfilename;std::stringmark;//eh头文件的标示std::stringsendAddr;//eh头文件的发送地址std::vector<std::string&g

dll结构体-C#调用DLL结构体,第一次成功,第二次的时候就报错。尝试读取或写入受保护的内存。

问题描述 C#调用DLL结构体,第一次成功,第二次的时候就报错.尝试读取或写入受保护的内存. C++代码 typedef struct tagIDCardData{ char Name[32]; //姓名 char Sex[6]; //性别 char Nation[20]; //名族 char Born[18]; //出生日期 char Address[72]; //住址 char IDCardNo[38]; //身份证号 char GrantDept[32]; //发证机关 char User