【发布时间】:2010-06-10 14:25:25
【问题描述】:
以下 .net 到本机 C 代码不起作用,任何想法
extern "C" {
TRADITIONALDLL_API int TestStrRef( __inout char* c) {
int rc = strlen(c);
std::cout << "the input to TestStrRef is: >>" << c << "<<" ;
c = "This is from the C code ";
return rc;
}
}
[DllImport("MyDll.dll", SetLastError = true)]
static extern int TestStrRef([MarshalAs(UnmanagedType.LPStr)] ref string s);
String abc = "InOut string";
TestStrRef(ref abc);
此时,Console.WriteLine(abc) 应该打印“This is from the C code”,但没有,有什么想法吗?
仅供参考 - 我有另一个不使用 ref 类型字符串的测试函数,它工作得很好
【问题讨论】:
-
首先让它在 C 中工作。
-
Native C - 它是 C .net - 不知道 :(
标签: c# c++ visual-studio-2008 visual-c++ pinvoke