1.方法中不要直接返回字符串,防止内存崩溃。
c++写法:
void necall(char* str1, char* outdata) {
strcpy(outdata, str1);
}outdata 为导出数
c#写法:
[DllImport("testdemo")]
private static extern void necall(string a,StringBuilder b); StringBuilder b = new StringBuilder();
necall("测试中", b);
c++的字符串导出需要用char*
std::string 转char*
const char* output1 = str.data();
strcpy(outdata, output1);