.CPP导出函数extern "C" WININETAPI wchar_t* ExportSession(CWininetHook* pObject,wchar_t* url)
{
if(pObject != NULL)
{
//return pObject->GetSession(url);
return url;
}
return NULL;
}C#调用函数  [DllImport("wh.dll")]
  static private extern string ExportSession(IntPtr p,string url );
C#和VC++都是在.NET4框架下.Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem in 'D:\SoftWare\WHC100504\WHC\Debug\MyIE.exe'.
Additional Information: A call to PInvoke function 'MyIE!MyIE.Form1::ExportSession' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

解决方案 »

  1.   

    怎么调用DLL引用,谁有没有DLL目录啊
      

  2.   

    C++中默认是_cdcel,.net中默认的是_stdcall
    [DllImport("wh.dll", EntryPoint="ExportSession", SetLastError=true,   CharSet=CharSet.Unicode, ExactSpelling=true,   CallingConvention=CallingConvention.Cdecl)] 
      static private extern string ExportSession(IntPtr p,string url );DllImport
    http://a18zhizao.com/y2009/1052_the-usage-of-c-dllimport.html
      

  3.   

    谢谢楼上,至少上面那个错误解决了!
    但又产生另外一个错误:Windows has triggered a breakpoint in MyIE.exe.This may be due to a corruption of the heap, which indicates a bug in MyIE.exe or any of the DLLs it has loaded.This may also be due to the user pressing F12 while MyIE.exe has focus.The output window may have more diagnostic information.还是不能得到我想要值,不知道从何入手?
      

  4.   

    我看不是stdcall和cdecl的错误,虽然这个也会造成堆栈不平衡……LZ你把你的代码贴出来  调用的时候 第一个参数要用非托管内存才行
      

  5.   

    The output window may have more diagnostic information.看看output窗口有没有更多的错误信息?