__stdcall ??

Please help me. I don't understand the line below
#define TX_FUNC __stdcall

Regards,
Hendra

Comments

  • [b][red]This message was edited by stober at 2005-6-20 1:53:57[/red][/b][hr]
    : Please help me. I don't understand the line below
    : #define TX_FUNC __stdcall
    :
    : Regards,
    : Hendra
    :
    From MSDN:
    [code] _cdecl calling function is responsible for cleaning up the stack.
    However, if _stdcall is used, the called function is responsible for
    cleaning up the stack. [/code]

    The line you quoted above simply redefines __stdall as TX_FUNC.





  • : Please help me. I don't understand the line below
    : #define TX_FUNC __stdcall
    :
    : Regards,
    : Hendra
    :

    [green]
    Stober is correct but I thought that I might break it down a little more for you.

    _stdcall is defined as this

    Parameters are pushed from right to left on the stack and the callee cleans up the stack. Windows API is an example of using this calling convention and you might of seen 'WINAPI' before WinMain which is defined simply as _stdcall.

    example
    [code]
    long _stdcall MY_FUNC([italic]long parameter 1, long parameter 2, long parameter 3[/italic])
    {
    ...some code
    }

    push parameter 3 /*ebp+16*/
    push parameter 2 /*ebp+12*/
    push parameter 1 /*ebp+8*/
    call MY_FUNC
    [/code]

    Nothing else needs to be done since the callee cleans up stack. The return value will be returned in the eax register.

    Now in C and other higher level languages functions use _cdecl unless otherwise specified. It is up to the caller to clean up the stack and the parameters are push right to left onto the stack just like _stdcall.

    example
    [code]
    long _cdecl MY_FUNC([italic]long parameter 1, long parameter 2, long parameter 3[/italic])

    push parameter 3
    push parameter 2
    push parameter 1
    call MY_FUNC
    add esp, 12
    [/code]

    Since I push 12bytes onto the stack, I had to add 12 back to the stack pointer to correct it or else my stack would be corrupt which would be very bad. The return value is going to be in the register eax.

    What does this mean? Nothing much to a high language programmer since the compiler handles all of this. All you have to do is tell the compiler if the function you made uses _cdecl, _stdcall, or some other calling convention.
    [/green]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories