Win32 Return Types

Started by
5 comments, last by Uphoreum 17 years, 2 months ago
I've noticed that some Win32 functions seem to have two return types, like: int WINAPI WinMain... and LRESULT CALLBACK WinProc... I'm pretty sure that the second "return types" aren't really return types, but if they're not, what are they? I've never seen two words preceding a function name outside of Win32.
Advertisement
The return types of those functions are int and LRESULT, respectively.
The 'keywords' WINAPI and CALLBACK indicate the calling convention used. The calling conventions describes how arguments are placed on the stack, and which registers of the CPU must be preserved.(More info: Wikipedia: x86 calling conventions). Note that WINAPI and CALLBACK actually are #defines for (OTOH) __stdcall and __cdecl.
Oh okay, I see. Thanks!
CALLBACK, WINAPI, PASCAL, and probably a few more that I cant remember right now are all #defined as __stdcall. None of them are #defined as __cdecl.
Isn't _stdcall the default for C++? Why would I need to add that in then?
My understanding is that cdecl is the default - "C decl". This, Calling Conventions Demystified, claims it's the default for C and C++.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Yep, you must be right. I took out the "WINAPI", and it gave me warnings about how WinMain had to be _stdcall.

This topic is closed to new replies.

Advertisement