Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在vc6中有win32 dll,并使用参数char*调用c#?_C#_C++_Dll_Visual C++ 6 - Fatal编程技术网

我在vc6中有win32 dll,并使用参数char*调用c#?

我在vc6中有win32 dll,并使用参数char*调用c#?,c#,c++,dll,visual-c++-6,C#,C++,Dll,Visual C++ 6,此vc6代码: MCASMARTMANAGER_API int __stdcall reqeustKey_test(char* prKey) { Xhandeler.GetPrimaryKey(prKey); return 0; } prKey = "AB472EDB9012" 这个C#代码: 我在注册表项{'上收到的运行时い㠶㐵䘷䘰䉆ㄴ㌰'}. 我做错了什么?首先,“请求”拼写错误 其次,c#字符串是unicode(16位)。VC6字符*是ASCII(8位)。您的

此vc6代码:

MCASMARTMANAGER_API int  __stdcall reqeustKey_test(char* prKey)
{    
    Xhandeler.GetPrimaryKey(prKey);
    return 0;
}

prKey = "AB472EDB9012"
这个C#代码:

我在注册表项{'上收到的运行时い㠶㐵䘷䘰䉆ㄴ㌰'}. 我做错了什么?

首先,“请求”拼写错误

其次,c#字符串是unicode(16位)。VC6字符*是ASCII(8位)。您的封送处理应该使用
marshallas(UnmanagedType.LPStr)


第三,返回类型不是字符串,而是int,应该作为
marshallas(UnmanagedType.I4)进行封送

我认为应该是一个
LPStr
而不是
LPWStr
。另外……如何从
int
封送
string
的返回值?我认为您的代码应该对
string prKey
参数使用
ref
。在使用非托管类型时。LPStr返回“”为空!?!!?如Alvin Wong指出,如果要设置
prKey
[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_);