int WINAPI WinMain // ...
int PASCAL WinMain // ...
Hello,
I'd like to know what do the "WINAPI" and "PASCAL" things mean and what purpose they serve. Are there any other like these?
Thanks for your replies!
int XXX WinMain
They are macros that (should) evaluate to something like __declspec(stdcall), specifying the calling convention that is standard to the Windows API.
See here for more.
edit: linked to MSDN rather than Wikipedia.
See here for more.
edit: linked to MSDN rather than Wikipedia.
Hey, thanks for that!
Now, I'd like to know something else: is it compulsory to tell the compiler the calling convention of the WinMain function?
Now, I'd like to know something else: is it compulsory to tell the compiler the calling convention of the WinMain function?
I "think" (and by think I mean am possibly talking out of the left edge of my ass) that it is there to tell certain Non-VS compilers what the convention is. In Visual Studio, it can be left out without any (that I know of) effect whatsoever.
In the project settings, you can set the default calling convention. I believe the default is cdecl, so if you need stdcall or something else, you'll either have to manually specify the alternate calling convention wherever you need it, or you will have to change the project-wide calling convention and use that everywhere (or manually specify cdecl when you want it).
Generally it's best to leave your project settings alone and just specify WINAPI before things like WinMain() and your window procedures.
I don't know if including the calling convention is necessary (it may well be depending on your compiler), but I believe including it explicitly the declaration is just good form.
It is for MSVC++ (I know because I forgot to write WINAPI when defining WinMain() today [smile])
Quote:Original post by JBourrie
I "think" (and by think I mean am possibly talking out of the left edge of my ass) that it is there to tell certain Non-VS compilers what the convention is. In Visual Studio, it can be left out without any (that I know of) effect whatsoever.
Not completely true. If you don't tell the calling convention, the compiler assume that you use the c calling convention - which is different from the stdcall one. Most WinAPI callbacks are supposed to be stdcall - if you feed a function with a callback that is not stdcall, you'll probably going to screw your stack and to crash.
Regards,
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement