Archived

This topic is now archived and is closed to further replies.

uNiQue0815

APIENTRY ?

Recommended Posts

if APIENTRY defined as __stdcall ? i didn''t find any documentation, neither in www, nor in any include-file or the msdn... if i don''t explicitely define a calling convention, which one is used for function calls ? (think, it should be __stdcall, but don''t know for sure...) let''s say i declare a function pointer... void (*function)(int a); ...and set its address manually (i.e. by loading a dll / getprocaddress())... when i make a call to function(1), which calling convention will be used THEN ? i had some problems assuming, that it''ll be __stdcall, but maybe someone can tell me...

Share this post


Link to post
Share on other sites
APIENTRY is defined in windef.h.

I would expect the default calling convention to be __cdecl, but on Windows it more likely to be __stdcall.

I would suspect that in the case of using GetProcAddress, the calling convention would be the same as the function obtained. However, GetProcAddress returns a FARPROC which is defined with the WINAPI calling convention (__stdcall) and I don''t think a cast changes that.

Share this post


Link to post
Share on other sites
You can't cast away the calling convention; if you try to call a function through a pointer that has a different calling convention, you could corrupt the stack and all sorts of wierd things can happen.

The calling convention is really only an issue if you are working on the same project with different compilers and/or different versions of the compilers, i.e. MSVC.NET + MSVC4. This also poses a problem if you distribute a library to someone using a different compiler or a different version of the same compiler.

In those cases you should use a preprocessor define to specify which calling convention you wish to use:
# define MYAPIFUNCTION __stdcall 
As far as the Windows defines related to calling conventions (i.e., APIENTRY, CALLBACK, etc.) you can avoid most of them without any immediate problems. However, when Windows goes 64-bit, your code will be much easier to port if you simply stick with the calling conventions Windows tells you to use for Windows-specific functions such as WinMain.

The calling convention for these special functions may change, and people who used the right preprocessor definitions can simply recompile their code for the new environment.

[edited by - null_pointer on July 18, 2002 3:42:05 PM]

Share this post


Link to post
Share on other sites