C#调用C++写的Dll时的运行时错误解决

两个错误:

 

1. Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call. This is usually a result of calling a function declared with one
calling convention with a function pointer declared with a different calling convention

 

先把dll的项目属性中C/C++->Code Generation->Basic Runtime Checks的属性改为Default

 

2. System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

查看一下你的dll中的函数,如果函数返回是采用某个局部变量,需要把这些返回的局部变量都声明为static

 

问题解决!!


posted @ 2011-06-21 17:01  Master HaKu  阅读(2824)  评论(0编辑  收藏  举报