【发布时间】:2012-11-29 06:51:35
【问题描述】:
这个vc6代码:
MCASMARTMANAGER_API int __stdcall reqeustKey_test(char* prKey)
{
Xhandeler.GetPrimaryKey(prKey);
return 0;
}
prKey = "AB472EDB9012"
还有这个 C# 代码:
[DllImport(McaSmartManagerDllPath, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
[return:MarshalAs(UnmanagedType.LPStr)]
public static extern string reqeustKey_test([MarshalAs(UnmanagedType.LPWStr), In, Out] string prKey);
var key_ = new string(' ', 17);
_strPrimaryKey = McaSmartNativeCommand.reqeustKey_test(key_);
我在 key_ {'い㠶㐵䘷䘰䉆ㄴ㌰'} 上收到的运行时。我做错了什么?
【问题讨论】:
-
我认为应该是
LPStr而不是LPWStr。另外...您如何从int编组string的返回值???我认为您的代码应该使用ref作为您的string prKey参数。
标签: c# c++ dll visual-c++-6