当前位置:编程学习 > C#/ASP.NET >>

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

我用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  其他信息: 尝试读取或写入受保护的内存”的错误,请问这是怎么回事啊? --------------------编程问答-------------------- [DllImport("SmartCom411SFJ.dll", CharSet = CharSet.Ansi)] 
static extern void affacting(string input,string output); 
试试,
如果不行, 把你的C++函数贴上来看看. --------------------编程问答--------------------
引用 1 楼 qqiuzaihui 的回复:
[DllImport("SmartCom411SFJ.dll"]
 static extern void affacting(string input,string output);
 试试,
 如果不行, 把你的C++函数贴上来看看.

[DllImport("affactingDll.dll", CharSet = CharSet.Ansi)] 
不好意思,动态库文件写错了. --------------------编程问答-------------------- http://topic.csdn.net/u/20090604/21/a31135af-e57b-4f3f-8ec3-5a714b802bbf.html --------------------编程问答-------------------- 来学习的…… --------------------编程问答-------------------- 得搞清楚谁分配内存,谁释放内存 --------------------编程问答-------------------- 是不是有可能引用dll的时候,函数的参数的类型不对啊。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,