我的DLL是在UNICODE下编程的,想输出一个字符给调用它的C#窗体,结果总是报错:"Windows 已在 MyIE.exe 中触发一个断点。其原因可能是堆被损坏,这说明 MyIE.exe 中或它所加载的任何 DLL 中有 Bug。原因也可能是用户在 MyIE.exe 具有焦点时按下了 F12。输出窗口可能提供了更多诊断信息。
"
.CPP导出函数extern "C" WININETAPI wchar_t* __stdcall ExportSession(CWininetHook* pObject,wchar_t* url)
{
if(pObject != NULL)
{
//return pObject->GetSession(url);
return url;
}
return NULL;
}C#调用函数声明:
[DllImport("wh.dll",CharSet=CharSet.Unicode,CallingConvention=CallingConvention.Cdecl)]
static private extern string ExportSession(IntPtr p, string url);调用:
string aa = ExportSession(this.m_pNativeObject, url);
"
.CPP导出函数extern "C" WININETAPI wchar_t* __stdcall ExportSession(CWininetHook* pObject,wchar_t* url)
{
if(pObject != NULL)
{
//return pObject->GetSession(url);
return url;
}
return NULL;
}C#调用函数声明:
[DllImport("wh.dll",CharSet=CharSet.Unicode,CallingConvention=CallingConvention.Cdecl)]
static private extern string ExportSession(IntPtr p, string url);调用:
string aa = ExportSession(this.m_pNativeObject, url);
static private extern IntPtr ExportSession(IntPtr p, string url);IntPtr aa = ExportSession(this.m_pNativeObject, url);
string bb= System.Runtime.InteropServices.Marshal.PtrToStringUni(aa);
LZ的是stdcall
[DllImport("wh.dll")]
static private extern IntPtr ExportSession(IntPtr p, string url);
//这样就好
public struct CWinetHook
{
//……
};CWinetHook h;
string url;
//……
IntPtr p = Marshal.AllocHGlobal(sizeof(CWinetHook));
Marshal.StructureToPtr(h, p, true);
IntPtr s = ExportSession(p, url);
string strRet = Marshal.PtrToStringUni(s);