LRESULT CALLBACK WndProc

This is a discussion on LRESULT CALLBACK WndProc within the Windows Programming forums, part of the Platform Specific Boards category; Isn't this the function header of a window's procedure (without the arguments)? I guess I understand that the return value ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    LRESULT CALLBACK WndProc

    Isn't this the function header of a window's procedure (without the arguments)? I guess I understand that the return value is going to be LRESULT (which, I assume, is an int). But, what is CALLBACK?

    So, let me get this straight, WinProcs are called when something is done to a window, right? Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    I think its a #define for _stdcall. This tells the compiler how to push the function parameters onto the stack.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Oh, so what you mean by this is that it tells compiler that this is the windows procedure? So, if you leave this CALLBACK out, then it won't be a winproc? It just tells that when a change in the window happens, this is the function to go to? Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    No not at all. Its just a calling convention.... here this might help...

    Microsoft Specific >

    The __stdcall calling convention is used to call Win32 API functions. The callee cleans the stack, so the compiler makes vararg functions __cdecl. Functions that use this calling convention require a function prototype. The following list shows the implementation of this calling convention.

    Element Implementation
    Argument-passing order Right to left.
    Argument-passing convention By value, unless a pointer or reference type is passed.
    Stack-maintenance responsibility Called function pops its own arguments from the stack.
    Name-decoration convention An underscore (_) is prefixed to the name. The name is followed by the at sign (@) followed by the number of bytes (in decimal) in the argument list. Therefore, the function declared as int func( int a, double b ) is decorated as follows: _func@12
    Case-translation convention None


    The /Gz compiler option specifies __stdcall for all functions not explicitly declared with a different calling convention.

    Functions declared using the __stdcall modifier return values the same way as functions declared using __cdecl.

    END Microsoft Specific

    Example
    In the following example, use of __stdcall results in all WINAPI function types being handled as a standard call:

    // Example of the __stdcall keyword
    #define WINAPI __stdcall
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, I'm not sure I understand. But this is what I go out of it:

    You're saying that CALLBACK is a #define of _stdcall. So, when you use CALLBACK, it is really declaring this function to be a function of the API? I'm not sure about that part.

    Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  6. #6
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    > so the compiler makes vararg functions __cdecl

    I also really don't understand this line.

    Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    at heart all its really saying is ....

    long _stdcall func(int a1,int a2,int a3)

    in this function the args will be pushed in this order....

    a3,a2,a1

    but

    long PASCAL func(int a1,int a2,int a3)

    in this func the args will be pushed in this order....

    a1,a2,a3.

    hth
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Why does it matter what order they are pushed on to the stack?
    1978 Silver Anniversary Corvette

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    if they were pushed a3,a2,a1 and then popped a3,a2,a1 the only variable that would be right would be a2 so of course it matters.
    The reason there are different conventions is mainly due to linking to functions that were written in another language such as assembly etc.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    This link explains the different conventions.
    zen

  11. #11
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I think I understand, but why didn't I ever have to worry about this until I got to Windows programming? Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  12. #12
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    why didn't I ever have to worry about this until I got to Windows programming?
    It still applies to console mode programs, but as you never have to change the calling convention you never see it. It's not something you have to worry about, normally the only time you have to explicitly use it is for WinMain() and any callback functions.

    btw I was unable to reply to your PM as you've chosen not to receive them.
    zen

  13. #13
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    > btw I was unable to reply to your PM as you've chosen not to receive them.

    Really? I must have undid that option by accident. Let me switch it back. Sorry about that.

    Thanks for the explanation!

    --Garfield
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. classmember WndProc isn't called ...
    By Greenhorn__ in forum Windows Programming
    Replies: 10
    Last Post: 07-19-2008, 12:40 PM
  2. Implant a callback inside a class
    By Rune Hunter in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2005, 08:20 PM
  3. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 08:23 AM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  5. using a window callback function like wndproc
    By canine in forum Windows Programming
    Replies: 3
    Last Post: 12-02-2001, 08:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21