APIENTRY

Started by
1 comment, last by Anon Mike 17 years, 12 months ago
Hi, I am trying to understand some C/C++ constructions, hope anyone can help me in some simple questions. First of all, in a function prototype like this: #ifdef __cplusplus extern "C" { #endif extern int APIENTRY pngLoadRaw(const char *filename, pngRawInfo *rawinfo); #ifdef __cplusplus } #endif For example. Why the extern "C" in the #ifdef __cplusplus directive? I know it is commonly used in C++ classes when C code is used. And what the APIENTRY keyword means? It is compile specific, is it in the C++ language? it seems to map to __stdcall. Where can I find more information about: __stdcall, __cdecl, __clrcall, etc... Thanks and sorry for the silly questions
[]sTúlio Caraciolo
Advertisement
The Win32 API was written using C not C++. This bring with it a few differences. The important difference in this case is the way that function arguments are passed onto the stack and who is responsible for cleaning the stack when the function returns. This is where __stdcall, __cdecl, __clrcall, __thiscall, etc. come in. C uses the __stdcall convention while C++ uses __cdecl and __thiscall.

MSDN on calling conventions

APIENTRY and many other Win32-isms like CALLBACK and WINAPI specify the calling convention for the function.
The extern C stuff is there so that if you are writing a C++ program you can still call win32 functions (which are written for C).

APIENTRY is there because Windows uses the stdcall calling convention. However you are not required to use stdcall for your own app. Basically it's saying "regardless of whatever convention you use internally, when calling this specific function you have to use stdcall".
-Mike

This topic is closed to new replies.

Advertisement