Name
StdCall Directive
Syntax
Subroutine declaration; stdcall;Description
The stdcall directive uses the Windows standard
calling convention: arguments are pushed onto the stack, starting
with the rightmost argument. The subroutine is responsible for
popping the arguments from the stack.
Functions return ordinal values, pointers, and small records or sets
in EAX and floating-point values on the FPU stack.
Strings, dynamic arrays, Variants, and large
records and sets are passed as a hidden var
parameter. This hidden parameter is the last parameter, so it is
pushed first onto the stack. If the subroutine is a method,
Self is pushed just before the function’s
var result (if one is needed).
Tips and Tricks
Use
stdcallfor subroutines you export from a DLL that will be called by other languages.Use
stdcallfor Windows callback functions.
Example
// Make a list of all the top-level windows.
function Callback(Handle: HWND; List: TStrings): LongBool; stdcall;
var
Caption: array[0..256] of Char;
Len: Integer;
Text: string;
begin
Len := GetWindowText(Handle, Caption, SizeOf(Caption)-1);
SetString(Text, Caption, Len);
List.Add(Text);
Result := True;
end;
...
EnumWindows(@Callback, LParam(ListBox1.Items));See Also
| CDecl Directive, Function Keyword, Pascal Directive, Procedure Keyword, Register Directive, SafeCall Directive |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access