以下.NET原生C代碼不工作,任何想法爲什麼這個顯式P/Invoke不起作用?
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)應打印「這是從C代碼」,但並沒有任何想法上怎麼了 ?
僅供參考 - 我沒有使用ref類型的字符串另一個測試功能,它工作得很好
請在C工作的第一位。 – 2010-06-10 15:23:35
本機C - 它確實 C .net - 不知道:( – Kumar 2010-06-11 13:25:40