Advertisement

PASCAL | WINAPI

Started by May 10, 2002 07:31 PM
3 comments, last by The Lion King 22 years, 9 months ago
Hi, In Win32 programming, we have to use either of these WinMain(), int WINAPI WinMain() or int PASCAL WinMain() I have read that these handles Message Ques. PASCAL handles last one first while WINAPI handles first come first serve. Is this the only difference between these two or there is another major difference between them? Or is there any other term we can also use here instead of WINAPI and PASCAL? I ... am ... the GAME!!! The Lion King
thats not true. the WINAPI, PASCAL are the same.

they both are a "call convention"
ok functions work like this some where in machine code is the asm for

call func

right?

cept say you had
int func (double, single)

that double and single has to get to the called function. there is more then one way to do that. you can order them different. you can return on the stack. return on the registers. does the function pop them off the stack. does the code that called the function pop them off the stack. lots of different things that make a calling convention.

the 2 most common are STDCALL (the C language call) and PASCAL. WINAPI happens to use the pascal calling convention. any function that has to be called back by the windows API needs to use the pascal calling convention. including ones written in C. so you decorate it with WINAPI and that tells the compilier "hey even though in im C++ call me like im in pascal"



Advertisement
quote:
Original post by declspec
the 2 most common are STDCALL (the C language call) and PASCAL. WINAPI happens to use the pascal calling convention. any function that has to be called back by the windows API needs to use the pascal calling convention. including ones written in C. so you decorate it with WINAPI and that tells the compilier "hey even though in im C++ call me like im in pascal"


Actually, the C calling convention is __cdecl, and __pascal was something Win16 used. Win32 uses __stdcall for everything except variable argument functions which physically can''t be anything but __cdecl.

If you''re wondering what the difference between these calling conventions is:

__cdecl: Caller pops arguments off the stack, args are pushed last to first, function name''s case is preserved, and a leading underscore is prepended to function''s name.

__pascal: Callee pops args, args are pushed first to last, function name is made all uppercase, no additions to the name

__stdcall: Callee pops args, args are pushed first to last, function name''s case is preserved, a leading underscore is prepended and a ''@'' followed by a number indicating byte count of all parameters passed are appended to the name.

__cdecl is the only calling convention allowing for variable number of parameters. __pascal and __stdcall are slightly faster than __cdecl in arg removal code. __stdcall provides a bit of safety against stack corruption by encoding total size of arguments a function expects into its name. Pick the one you like more.
---visit #directxdev on afternet <- not just for directx, despite the name
thanks
__fastcall is another one. I believe it pushes n amount of arguments into registers if possible. In MSVC n is 2, and in Borland it is 3.

- Kevin "BaShildy" King
Game Programmer: DigiPen
www.mpogd.com
- Kevin "BaShildy" KingGame Programmer: DigiPenwww.mpogd.com

This topic is closed to new replies.

Advertisement