PInvokeStackImbalance错误?VC函数调用这样有问题吗?
CPP:
extern "C" WININETAPI CWininetHook* CreatClass()
{
return new CWininetHook();
}
extern "C" WININETAPI char* ExportSession(CWininetHook* pObject,char* url)
{
if(pObject != NULL)
{
returnpObject->GetSession(url);
}
return NULL;
}
C#:
[DllImport("wh.dll")]
static private extern IntPtr CreatClass();
[DllImport("wh.dll")]
static private extern string ExportSession(IntPtr p,string url );
提示:
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.
我的版本是.NET4,VS2010,在另台式机上,VS2008没有提示,上面兼装.NET1,有人说是因为64BIT与32BIT的问题,希望有朋友可以教我怎么改
[解决办法]
http://topic.csdn.net/u/20100422/21/9856050f-a224-4099-b615-68cf98a55497.html
"项目"---"属性"---"生成"中将"Any CPU"改为x86试试.
因为DLL还是32位的,在64位的系统上,IntPtr 占用8byte,比32位的系统多占4byte,所以堆栈失去平衡。