C#调用C++DLL出现未处理的“System.AccessViolationException”类型的异常出现在.exe其他信息: 尝试读取或写入受保护的内存

pingpeace 2009-09-25 11:05:25
我用C++写了处理程序 ,用C#写了界面,C#运行时出错。

string text_input;
string text_output="hello";
[DllImport("affactingDll.dll")]
static extern void affacting(ref string input,ref string output);

结果运行到调用下面语句 affacting(ref text_input, ref text_output) 时,出现“ 未处理的“System.AccessViolationException”类型的异常出现在.exe 其他信息: 尝试读取或写入受保护的内存”的错误,请问这是怎么回事啊?
...全文
1759 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
段段来了 2012-05-24
  • 打赏
  • 举报
回复
是不是有可能引用dll的时候,函数的参数的类型不对啊。
蒋晟 2009-09-25
  • 打赏
  • 举报
回复
得搞清楚谁分配内存,谁释放内存
binhu12332100 2009-09-25
  • 打赏
  • 举报
回复
来学习的……
qqiuzaihui 2009-09-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 qqiuzaihui 的回复:]
[DllImport("SmartCom411SFJ.dll"]
static extern void affacting(string input,string output);
试试,
如果不行, 把你的C++函数贴上来看看.
[/Quote]
[DllImport("affactingDll.dll", CharSet = CharSet.Ansi)]
不好意思,动态库文件写错了.
qqiuzaihui 2009-09-25
  • 打赏
  • 举报
回复
[DllImport("SmartCom411SFJ.dll", CharSet = CharSet.Ansi)]
static extern void affacting(string input,string output);
试试,
如果不行, 把你的C++函数贴上来看看.

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧