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?
相关问题
- Inheritance impossible in Windows Runtime Componen
- how to get running process information in java?
- Is TWebBrowser dependant on IE version?
- How can I have a python script safely exit itself?
- I want to trace logs using a Macro multi parameter
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Bundling the Windows Mono runtime with an applicat
- Windows 8.1 How to fix this obsolete code?
- CosmosDB emulator can't start since port is al
- How to print to stdout from Python script with .py
- Determine if an executable (or library) is 32 -or
cdecl and stdcall are by definition incompatible. In cdecl, the caller cleans up the stack, in stdcall the callee cleans up the stack. If you assume stdcall, but it is in fact cdecl, no one cleans up the stack. That means your ESP (stack pointer) is going to be screwed up after the call. Maybe if you give more details, there maybe a work around, but there is no way to call a function without knowing it's calling convention without messing up your stack.
See : http://en.wikipedia.org/wiki/X86_calling_conventions for a definition of the difference.
It can be done following way:
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.
Good, the order of the arguments is the same for CDECL and STDCALL - in reverse order.
You can also use alloca() which has the side effect of saving and restoring the stack pointer: