stdcall
Specifies a stdcall-style calling convention in a procedure declaration
Syntax
`
Declare [Static] Sub procedure_name [Overload] stdcall [Alias "external_name"] [([parameter_list])] [Constructor [priority]] [Static] [Export]
Declare [Static] Function procedure_name [Overload] stdcall [Alias "external_name"] [([parameter_list])] As return_type [Static] [Export]
[Public|Private] Sub procedure_name [Overload] stdcall [Alias "external_name"] [([parameter_list])] [Constructor [priority]] [Static] [Export]
..procedure body..
End Sub
[Public|Private] Function procedure_name [Overload] stdcall [Alias "external_name"] [([parameter_list])] As return_type [Static] [Export]
..procedure body..
End Function
`
Description
In procedure declarations, `stdcall` specifies that a procedure will use the stdcall calling convention. In the stdcall calling convention, any parameters are to be passed (pushed onto the stack) in the reverse order in which they are listed, that is, from right to left. The procedures need not preserve the `EAX`, `ECX` or `EDX` registers, and must clean up the stack (pop any parameters) before it returns.
`stdcall` is not allowed to be used with variadic procedure declarations (those with the last parameter listed as "`...`").
stdcall is the default calling convention for procedures not declared with a calling convention specifier, or that are declared within `Extern "Windows"` blocks. stdcall is also the standard calling convention used in BASIC languages, and the Windows API.
Example
`
Declare Function Example stdcall (param1 As Integer, param2 As Integer) As Integer
Declare Function Example2 cdecl (param1 As Integer, param2 As Integer) As Integer
Function Example (param1 As Integer, param2 As Integer) As Integer
' This is an STDCALL function, the first parameter on the stack is param2, since it was pushed last.
Print param1, param2
Return param1 Mod param2
End Function
Function Example2 cdecl (param1 As Integer, param2 As Integer) As Integer
' This is a CDECL function, the first parameter on the stack is param1, since it was pushed last.
Print param1, param2
Return param1 Mod param2
End Function
`
Platform Differences

- On Dos and Windows systems, stdcall procedures append an "@N" decoration to the internal/external procedure name, where N is the size of the parameter list, in bytes.
- On Linux systems, stdcall procedures are the same as cdecl procedures (see cdecl, Extern "C"), except that variadic procedures are still not allowed.

Differences from QB

- New to FreeBASIC

See also

- pascal, cdecl
- Declare
- Sub, Function