int XXX WinMain

Started by
9 comments, last by yadango 17 years, 11 months ago
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!
Advertisement
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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?
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.

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/

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).
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
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,
OK then, so I'd better just specify it for better compatibility ;)
Thanks!

This topic is closed to new replies.

Advertisement