问题描述
我需要写code调用,可以在32位Windows应用程序,无论是STDCALL调用或CDECL外部函数。结果
我的code,来电,也不能提前知道哪个这些公司将是。
现在,如果我尝试调用从被定义为STDCALL调用网站的cdecl函数,我得到一个checkEsp例外对话框,然后我猜这是有一个很好的理由。结果
有没有办法做到这一点?
I need to write code that calls an external function that can be either stdcall call or cdecl in a 32bit windows application.
My code, the caller, can't know in advance which of these its going to be.Right now, if I try to call a cdecl function from a call site that was defined as stdcall, I get a checkEsp exception dialog, and I'm guessing that's there for a good reason.
Is there any way to do it?
推荐答案
它可以下列方式进行:
mov esi, esp
push arg3
push arg2
push arg1
call [SomeExternalProc]
mov esp, esi ; now the stack is always properly cleaned
外部程序应preserve ESI。或者你可以使用由外部程序,甚至内存变量pserved任何其他寄存器$ P $ - 局部或全局
The external procedure should preserve esi. Or you can use any other register preserved by the external procedure or even memory variable - local or global.
好,参数的顺序是CDECL和STDCALL一样 - 以相反的顺序
Good, the order of the arguments is the same for CDECL and STDCALL - in reverse order.
这篇关于调用一个函数,它可以是的cdecl或STDCALL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!