C#调用C++接口的bug

来源:互联网 发布:聚丰网络车销 编辑:程序博客网 时间:2024/04/29 06:29
C#在调用C++的接口时,经常出现这样的错误:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。Attempted to read or write protected memory. This is often an indication that other memory is corrupt.其原因就是在在调用C++接口时,C#中参数务必要分配给它们内存。比如在C++中的接口为 bool getUserName(int userID,ref string userName)则在C#中声明string userName = new string(' ',50),然后再调用 getUserName(123,userName )即可。
原创粉丝点击