Jump to content
  • Advertisement
Sign in to follow this  
tulio

APIENTRY

This topic is 4591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!