急。。急:一个有关截获API函数的问题

njiceshihong8 2003-06-12 10:18:49
我在一个钩子DLL中实现了对API函数--MessageBoxA()的截获;如果我把自己的MessageBoxA函数--MyMessageBoxA()的调用约定定义为__cdecl,即
int __cdecl MyMessageBoxA(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType),则会报错“Access violation at address 00000000.Read of address 00000000”;而如果将MyMessageBoxA()的调用约定定义为__stdcall,即
int __stdcall MyMessageBoxA(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType),则不会报错。

请问为什么?
...全文
90 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
888888888888 2003-06-13
  • 打赏
  • 举报
回复
同意楼上
Purple_Z 2003-06-13
  • 打赏
  • 举报
回复
这两种调用的压栈方式不同的,即参数压入的顺序有所不同,另外还有一些其他的小差别
nnfish 2003-06-12
  • 打赏
  • 举报
回复
在dll中用不同的调用方式声明的函数,是要用不同的调用方式来调用,否则就出错。


例如Win32 API就应该用__stdcall方式来调用呀,,呵呵
nnfish 2003-06-12
  • 打赏
  • 举报
回复
以下是delhpi的在线帮助:

The table below summarizes calling conventions.

Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
cdecl Right-to-left Caller No
stdcall Right-to-left Routine No
safecall Right-to-left Routine No

The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.)

The cdecl convention is useful when you call functions from DLLs written in C or C++, while stdcall and safecall are used for Windows API calls.

The safecall convention must be used for declaring dual-interface methods.

The pascal convention is maintained for backward compatibility.

明白了吧,呵呵:)

1,222

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧