【转】http://www.cnblogs.com/davidgu/archive/2011/06/21/2086202.html C#调用C++写的Dll时的运行时错误解决 两个错误: 1. Run-Time Check Failure #0 - The value of ESP was not properly saved across afunction call. This is usually a result of calling a function declared with onecalling 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 问题解决!! 转载于:https://www.cnblogs.com/zhb/archive/2012/09/03/2668880.html