Skip to main content
gamedev.net
🔒 Locked

WINAPI

Started by merwin Oct 10, 2001 at 1:02 PM 4 replies 500+ views
Original Post
merwin
merwin
I''m trying to learn programming in visual c++. I''ve bought serveral books but just one questions keeps unanswered. Why look most WinMain functions like this: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow); instead of: int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow); Thanks for your attention on this..
Oluseyi
Oluseyi
WinMain() is not the same thing as main(), so their declaration parameters are different. As the Anonymous Poster said, it has to do with the order of parameter passing onto the stack. WINAPI is the same as what used to be __far __pascal, but __far is obsolete on 32-bit systems (because there are no longer near- and far-data segments). The Win32 API actually has no documentation for __pascal either (and since I never used it when I programmed 16-bit DOS, I have no idea what it does).

WINAPI and other calling conventions define prologue and epilogue code - stuff the compiler/assembler will do before and after your function. For now, just know that WinMain is int WINAPI.
noparity
noparity
If you look in windef.h, you will find the following:
  
#define WINAPI __stdcall


In a __stdcall function, the function (callee) is responsible for cleaning up the stack. On the other hand, the C calling convention __cdecl requires the caller to clean up the stack. To the best of my knowledge, all Windows API functions use the __stdcall calling convention unless the function takes variable arguments(uses __cdecl).
Dactylos
Dactylos
quote:
Original post by Oluseyi
[...] but __far is obsolete on 32-bit systems (because there are no longer near- and far-data segments).

On a 32 bit x86 system (IA-32), there are still near and far pointers (intra-segment and inter-segment pointers respectively). It''s just that since Windows uses a flat memory model the far pointer is pretty useless. (Flat memory model means that all segments are aliases of each other, i.e. they all begin at offset 0, with a segment limit of FFFFFFFF.)

Oluseyi
Oluseyi
My bad, I meant 32-bit flat memory addressing model (the core difference between 16- and 32-bit DOS and Windows, other than the Windows executive).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.