C++ dll中导出函数:
extern "C" __declspec(dllexport) CString exportSession(CString url)
{
CString session=CRequest.GetSession(url);
return session;}
C#调用函数: [DllImport("wh.dll")]
static private extern string exportSession(string url); string bb = exportSession("http://community.csdn.net/");
结果传到C++函数中,看到URL是乱码,不知怎么回事?怎么修改
extern "C" __declspec(dllexport) CString exportSession(CString url)
{
CString session=CRequest.GetSession(url);
return session;}
C#调用函数: [DllImport("wh.dll")]
static private extern string exportSession(string url); string bb = exportSession("http://community.csdn.net/");
结果传到C++函数中,看到URL是乱码,不知怎么回事?怎么修改
static private extern string exportSession(string url);
static private extern string exportSession([MarshalAs(UnmanagedType.LPStr)]string url);
[DllImport("wh.dll", CharSet = CharSet.Ansi)]
static private extern string exportSession(string url);
那把 CallingConvention=CallingConvention.Cdecl也加上去看看试了,也不行。是不是兼容的问题
extern "C" __declspec(dllexport) char * __stdcall exportSession(char *url)
{
}
C#调用函数: [DllImport("wh.dll")]
static private extern StringBuilder exportSession(StringBuilder url);
不是说了吗,CString 可是MFC特有的,char *是C语言中的基本类型,其它的平台都支持,改成这样方便跨平台调用.CString 只有MFC平台才支持,其它平台使用就会出问题的,不通用.
系统的DLL中也都是用char *的
extern "C" __declspec(dllexport) char * __stdcall exportSession(char *url)
{
}
C#调用函数: [DllImport("wh.dll")]
private static extern StringBuilder exportSession(StringBuilder url);
__cdecl
__pascal
在网上查找这几个关键字,看看都是干什么的。
其他的就要靠经验的积累了。