user497849
user497849

Reputation:

stdcall required on import function?

I'm curious about this:

When I import a function from a dynamic link library that exports using stdcall calling convention, is it mandatory to add stdcall before external in Delphi starting from version 7?

i.e.

LIBNAME int __stdcall Foo(void);

as

function Foo: Integer; stdcall; external 'libname.dll';

or I can get away with just

function Foo: Integer; external 'libname.dll';

IIRC by default it will use stdcall but I'm not 100% sure on this, your opinion is required.

EDIT:

The question is related to 32bit library, Arnaud Bouchez has made a good point that for 64bit, the calling convention is not taken into consideration since there's only one.

Upvotes: 4

Views: 6216

Answers (1)

David Heffernan
David Heffernan

Reputation: 613382

If you omit stdcall then the default calling convention register will be used. So you must include that stdcall.

The fact that you are using external does not change anything. The default calling convention is register, even for external imports.

Of course, this only matters when compiling for 32 bit. On x64 Windows there is a single calling convention specified in the ABI. On x64 Windows, all calling conventions specified in code are ignored and all function calls are made with the Windows x64 calling convention.

Upvotes: 11

Related Questions