Advertisement

CALLBACK or WINAPI

Started by June 05, 2000 02:11 AM
7 comments, last by Digger 24 years, 6 months ago
Is there any difference between CALLBACK and WINAPI. In DirectDraw I use WINAPI in the function header, like it says in the documentation, but many programmers out there use CALLBACK instead. Which should I use, because I have some problems with the enumeration???
The windows compiler I use defines them both as __stdcall, so there should be no difference.
Advertisement
From the MSDN library:

WINAPI Use in place of FAR PASCAL in API declarations. If you are writing a DLL with exported API entry points, you can use this for your own APIs.

CALLBACK Use in place of FAR PASCAL in application callback routines such as window procedures and dialog procedures.
What exactly do these WINAPI CALLBACK __stdcall __fastcall and all these other stuff (which I don''t know what they are called) do?
__fastcall, __stdcall, __cdecl, __pascal are just different calling conventions for functions. i am not sure how all of them work exactly.

i believe this is how they work.

__pascal:

"pascal" calling convention. cannot have a random number of arguments. pushes arguments onto the stack in order. the called function must clean up the stack.

__cdecl:

"c" calling convention. can have a random number of arguments. pushes arguments onto the stack in order. the calling function must clean up the stack.

__stdcall:

i don''t know.

__fastcall:

uses certain registers to pass arguments instead of pushing them onto the stack.

FAR: means the call is to a function in another segment selector.

NEAR: means the call is to a function within the same segment selector.

-------------------------

stuff like WINAPI, CALLBACK, or PASCAL are just type redefinitions.

hope this helps.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Thanks.

But one more problem is that I don''t know what stacks is.
And what does "push the arguments onto the stack in order" mean?
Advertisement
Hi MrCucumber,

The stack is a volatile memory where its work like a FILO list...

ie : when you put something on the stack, you place it over the last item pushed on the stack, so when you get from the stack you get your item in the inverse order.

if i want to xchg register (witch is small memory (byte, word, dword on the processeur) without using xchg call) you can do this:


push ax;//send ax value to the stack (item 1)
push bx;//send bx value to the stack (item 2)
push cx;//send cx value to the stack (item 3)

i want to inverse the order of the register so..
pop ax;//get item 3 from the stack
pop bx;//get item 2 from the stack
pop cx;//get item 1 from the stack...

Lowrad,
The _pascal calling convention is no longer supported by MSVC.

_cdecl calling convention passes arguments right to left and the calling function cleans the function arguments from the stack.

_stdcall calling convention passes arguments right to left and the called function cleans the function arguments from the stack.

_fastcall calling convention passes the first two DWORD or smaller arguments into ECX and EDX and passes the rest from right to left on the stack. The called function cleans the function arguments from the stack.

There''s a few more details on another thread in this board about calling conventions.
Although this is an interesting discussion it doesn''t belong in the DirectX/OpenGL forum so I''m moving it

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement