APIENTRY

APIENTRY
Post New Topic Post Reply 

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

 User Rating: 1010   |  Rate This User Send Private MessageView ProfileReport this Post to a Moderator | Link

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.


Less Than Enlightened

 User Rating: 1660   |  Rate This User Send Private MessageView ProfileView JournalView GD Showcase EntriesReport this Post to a Moderator | Link

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".

 User Rating: 1604   |  Rate This User Send Private MessageView Profile
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值