2011-10-05 49 views
0

当我尝试运行以下函数时,出现以下错误。否则,在完成函数过程时,我收到错误。调试错误!函数调用时ESP的值不正确

Debug error! 

The value of ESP was not properly saved across a function call. 
This is usually a result of calling a function declered with one calling 
convention with a fonction pğointer declered with a different calling convention. 

代码:

typedef int(*FPROC)(char*,char*,char*,char*,char*,int,int); 
HINSTANCE hDllInstance; 
FPROC pmyfonk; 
hDllInstance = LoadLibrary(TEXT("mydll.dll")); 
if (hDllInstance==NULL) {MessageBox("...dll yok............"); 
exit(0); 
} 

pmyfonk=(FPROC)GetProcAddress(hDllInstance,TEXT("myfonk")); 
pmyfonk(TEXT("xxx"),TEXT("xxy"),TEXT("xxz"),NULL,TEXT("xy"),1,1);//this function is working.But,I'm getting upper error. 

FreeLibrary(hDllInstance); 
+1

你能展示DLL的函数声明吗? –

+0

有何建议? – user980020

+0

@ user980020实际上没有'GetProcAddress'的unicode版本,所以你不应该使用'TEXT()'宏作为它的第二个参数。另外,因为函数类型'FPROC'只接受'char *',所以在调用'pmyfonk'时不应该使用宏,否则当'UNICODE'被设置时编译将失败。 –

回答

2

你应该检查了这一点:http://msdn.microsoft.com/en-us/library/k2b2ssfy.aspx

有一个在你的代码某处调用约定不匹配。我是Windows编程的新手,所以我不知道更多,但这显然是错误信息告诉的。

+0

myfonk的签名不是FPROC,他可能缺少'__cdecl'或'__stdcall',不知道是哪一个。 –

3

默认情况下,使用__cdecl调用约定。我想你的DLL函数使用__stdcall约定。不同之处在于必须使用__cdecl和__stdcall通过调用者清理堆栈。我认为你搞砸了这样的事情。 Here you can find这些惯例的很好的解释。

相关问题