帮我解释一下在delphi中的stdcall到底是什么意思?(20分)

  • 主题发起人 靖哥哥
  • 开始时间

靖哥哥

Unregistered / Unconfirmed
GUEST, unregistred user!
to::卷起千堆雪tyn 回调函数又是什么意思?
 
卷起千堆雪: 我不同意你的观点。记得以前在一本c++的书上看到过,stdcall指的是函数
调用时候的参数传递方式。c,c++传递参数的时候是从参数列表的右边线左边传递,也就是
用的堆栈的方式;而delphi是用的pascal的参数传递方式,是从左向右传递的。所以在
delphi中如果涉及到调用.dll之类的,就要用stdcall指明参数传递方式。
 
hehe,卷起千堆雪,这次你可翻了船,stdcall与callback是两回事.
stdcall是标准调用,也就是说采用标准windows参数传递方式来调用函数.
几种调用方式详细说明如下:
When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall. For example,
function MyFunction(X, Y: Real): Real;
cdecl;
...
Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register.
The register and pascal conventions pass parameters from left to right;
that is, the leftmost parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left.
For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns.
The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.
The safecall convention implements COM error and exception handling.
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. For more information on calling conventions, see Program control.
The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only.
 
看来我今天是庆祝生日胡涂了,唉~~~
 
看来还是popeye和sonie说的对,同时祝卷起千堆雪tyn生日快乐!
 
顶部 底部