c#调用DLL尝试读取或写入受保护的内存。这通常指示其他内存已损坏 1.如果dll中的函数参数含有var,则c#中要加上ref(引用);否则,会有提示错误:“尝试读取或写入受保护的内容。这通常指示其他内存已损坏”。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20100609/14/b6f8e741-7fbd-4286-8478-b8b3ded50bea.html 楼主补充 我是调用function InceptData(const handle:THandle):integer; function ReadInfo(const :integer;const id:integer;d1:PChar;d2:PChar;d3:PChar;d4:PChar;d5:PChar;d6:PChar;d7:PChar; d8:PChar;d9:PChar;d10:PChar;d11:PChar;d12:PChar;d13:PChar;d14:PChar;d15:PChar;d16:PChar):integer;stdcall;这两个方法出错用C#定义如下 //接收数据函数 =0成功;=1失败 =11 接收失败 =12 接收头错误 =5 超时错误 [DllImport("Project2.dll")] private static extern int InceptData( IntPtr handle); function ReadInfo(const :integer;const id:integer;d1:PChar;d2:PChar;d3:PChar;d4:PChar;d5:PChar;d6:PChar;d7:PChar; d8:PChar;d9:PChar;d10:PChar;d11:PChar;d12:PChar;d13:PChar;d14:PChar;d15:PChar;d16:PChar):integer;stdcall; [DllImport("Project2.dll")] private static extern int InceptData( IntPtr handle);为什么要用Private呢? 是不是c#中调用函数语句有错?或者你的dll没放对位置? 我调用 [DllImport("Project2.dll")] private static extern int Init(int CDT); //释放对象 =0成功;=1失败 [DllImport("Project2.dll")] private static extern int UnInit(); //主机初始化com口函数 =0成功;=1失败 [DllImport("Project2.dll")] private static extern int InitCom(string comid);没有问题就是刚才我发的那两个函数有问题 [DllImport("Project2.dll",CharSet=CharSet.ansi)]试下行不 自己用dll建立新的project调用自己的dll看存在问题否!delphi中有个内存管理模块叫borlandmm.dll,在你写的函数中,使用到了string,那么就可能 use 这个单元,但这只适合delphi调用(内存共享管理单元),建议重构delphi中导出函数,去掉string,改为pchar,或者其它。当然你可以加入borlandmm单元然后再测试下。使用delphi进行调试dll,找到报错地址后再进行分析。顺遍请楼主把调用堆栈贴出来看看把 C#窗体应用返回值显示求助 C#asp.net问题. c#的转换小问题 如何使用C#语言访问java开发的Web服务 救急啊 浏览刚发布的网站出现出错,请指点 请问静态变量何时释放 紧急求助,怎样用同一个assembly 安装多个名字不同的Windows Service? 用水晶报表时老是有个登陆框要用户输入密码等等,我的程序中已经知道,想禁止这个弹出框,怎么办? 高分求助一个隐藏列的问题 怎么解析一个查询字符串 C#中devenv.exe—应用程序错误 给为C#前辈,小弟菜鸟,问一个简单的问题,不要笑~~
我是调用function InceptData(const handle:THandle):integer;
function ReadInfo(const :integer;const id:integer;d1:PChar;d2:PChar;d3:PChar;d4:PChar;d5:PChar;d6:PChar;d7:PChar;
d8:PChar;d9:PChar;d10:PChar;d11:PChar;d12:PChar;d13:PChar;d14:PChar;d15:PChar;d16:PChar):integer;stdcall;
这两个方法出错用C#定义如下
//接收数据函数 =0成功;=1失败 =11 接收失败 =12 接收头错误 =5 超时错误
[DllImport("Project2.dll")]
private static extern int InceptData( IntPtr handle);
function ReadInfo(const :integer;const id:integer;d1:PChar;d2:PChar;d3:PChar;d4:PChar;d5:PChar;d6:PChar;d7:PChar;
d8:PChar;d9:PChar;d10:PChar;d11:PChar;d12:PChar;d13:PChar;d14:PChar;d15:PChar;d16:PChar):integer;stdcall;
private static extern int InceptData( IntPtr handle);
为什么要用Private呢?
或者你的dll没放对位置?
[DllImport("Project2.dll")]
private static extern int Init(int CDT);
//释放对象 =0成功;=1失败
[DllImport("Project2.dll")]
private static extern int UnInit(); //主机初始化com口函数 =0成功;=1失败
[DllImport("Project2.dll")]
private static extern int InitCom(string comid);没有问题
就是刚才我发的那两个函数有问题
[DllImport("Project2.dll",CharSet=CharSet.ansi)]试下行不
delphi中有个内存管理模块叫borlandmm.dll,在你写的函数中,使用到了string,那么就可能 use 这个单元,但这只适合delphi调用(内存共享管理单元),建议重构delphi中导出函数,去掉string,改为pchar,或者其它。
当然你可以加入borlandmm单元然后再测试下。使用delphi进行调试dll,找到报错地址后再进行分析。顺遍请楼主把调用堆栈贴出来看看把