What does it mean Call Back modifires in WinMain() function??
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: What does it mean Call Back modifires in WinMain() function??

  1. #1
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    What does it mean Call Back modifires in WinMain() function??

    I have one question about Call Back modifires , for example
    to write winMain() Function the syntax is :

    int WINAPI winMain(){}

    and I read in many books WINAPI = it is a callback modifires which calls function _stdcall...

    I review many time C & C++ language I could not find any thing by this description " CALLBACK"..
    I am familir with c/c++ functions and I know Macros that can be defined by using #define statment...

    Kindly if any one can expalin this concpet in simple way to scratch this basic point for winAPI function..

    Also I read in one book .. this is a syntax to call function by using Pascal Language ?? But as I know WinAPI is written by C language..

    I hope I will get a good explanations for this point..

    My Best Regards..

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,544

    Re: What does it mean Call Back modifires in WinMain() function??

    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,051

    Re: What does it mean Call Back modifires in WinMain() function??

    Quote Originally Posted by mecheil.edwar View Post
    I have one question about Call Back modifires , for example
    to write winMain() Function the syntax is :

    int WINAPI winMain(){}

    and I read in many books WINAPI = it is a callback modifires which calls function _stdcall...

    I review many time C & C++ language I could not find any thing by this description " CALLBACK"..
    CALLBACK has nothing to do with C or C++. It's not a part of language, it's a Windows Platform SDK thing. So, wrong place to look up in.

    I am familir with c/c++ functions and I know Macros that can be defined by using #define statment...

    Kindly if any one can expalin this concpet in simple way to scratch this basic point for winAPI function..
    Code:
    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include>grep -n "define CALLBACK " win*.h
    wincrypt.h:51:#define CALLBACK __stdcall
    windef.h:112:#define CALLBACK    PASCAL
    windef.h:123:#define CALLBACK    __stdcall
    Also I read in one book .. this is a syntax to call function by using Pascal Language ?? But as I know WinAPI is written by C language...
    It doesn't matter what language it was written in. There are lots of languages that are able to call Win32 API functions, including Pascal of course.
    Last edited by Igor Vartanov; August 24th, 2012 at 05:56 PM.
    Best regards,
    Igor

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,639

    Re: What does it mean Call Back modifires in WinMain() function??

    As far as i know, back in the days of early Windows Pascal was the only language where the called function cleaned up the stack. Since that was a bit more efficient than both the caller and the callee cleaning up their parts MS choose the Pascal way for the API calls. Also, since this was in the 16 bit segment/offset time all API functions where specified as FAR PASCAL. In these days it's replaced with WINAPI which translates to _stdcall which makes the callee to clean up the stack, i.e. abit more efficient than _cdecl where the stack cleanup is done by both the caller and the callee.
    Last edited by S_M_A; August 25th, 2012 at 04:47 AM.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  5. #5
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    Re: What does it mean Call Back modifires in WinMain() function??

    Thank you to all my colleagues for venerable and wonderful answers,
    Thanks to Victor ,and Thanks Igor for your effective clarifications, and thanks to S_M_A,

    and now ,I have one other question :
    I see this code :
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

    and during debbing I can see this statement :
    #define CALLBACK_stdcall;

    My question is : during debbing proccessing ; is it possible to see further more about _stdcall during debbing or this is just internal proccessing between windows itself and my application...

    My Best Regards,,

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,544

    Re: What does it mean Call Back modifires in WinMain() function??

    Quote Originally Posted by mecheil.edwar View Post
    My question is : during debbing proccessing ; is it possible to see further more about _stdcall during debbing or this is just internal proccessing between windows itself and my application...
    Excuse me, but what is the "debbing proccessing"?
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    Re: What does it mean Call Back modifires in WinMain() function??

    Sorry .. I mean during Debugging Proccessing..
    (Note I am using Visual Studio 2012)

  8. #8
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,639

    Re: What does it mean Call Back modifires in WinMain() function??

    I'm not sure what you're after here but if you want see more details about the different call types you have to open the disassembly view (Alt+8) while debugging.
    Instead of stepping the windows API in assembly, make a couple of functions yourself where you can vary number of parameters and local variables to view what effect that has on the assembly.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,051

    Re: What does it mean Call Back modifires in WinMain() function??

    Quote Originally Posted by mecheil.edwar View Post
    My question is : during debbing proccessing ; is it possible to see further more about _stdcall during debbing or this is just internal proccessing between windows itself and my application...
    If you give us a chance to understand what "further more about _stdcall" really is and how seeing it relates to "internal processing" and "during debugging", maybe you get your answer...
    Best regards,
    Igor

  10. #10
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    Re: What does it mean Call Back modifires in WinMain() function??

    Hi Igor and thank you and thanks for all my colleagues for helping ..

    What I mean Exactly..
    when I start Debugging the Win32 Application I note the followings..
    All The WinAPI Functions as example :
    ATOM MyRegisterClass();
    LRESULT CALLBACK WndProc();
    INT_PTR CALLBACK About();

    All of these Functions are written in code as a prototype function , I mean when I declare any function I see as Example ; int Function1(...);
    This is the prototype , or declaration of function .. ok...

    So , When We write the win32 Application we declare as example wndProc function , and we write :
    LRESULT CALLBACK WndProc();
    Now when I start Debug , I see a pointer to every WinAPI Function I declared ..
    for example I can see the address of WndProc Function , the Address of About function and so , and so..
    When I asked about _stdcall , Igor and other colleagues said that , this is a standard call of function (between Operating system and my Application )
    My Question is , If I can see the address of each WinAPI Function .. can I go further more .. and see in more detail .. how this function is working?? or this is a low level layer between operating system and the code of program...
    in other words .. I think I can go in more details to see the as example the function WndProc() and see the code of this function and how it is working...

    Sorry , because I am New Learner ..
    I hope my question is clear ..
    My Best Regards to All

  11. #11
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,544

    Re: What does it mean Call Back modifires in WinMain() function??

    If what you meant is "is it possible to see the source code of some Windows API?" then the answer would be:
    no, it is (in the most if not the all cases( not. Microsoft does not supply source code for Windows APIs.
    Victor Nijegorodov

  12. #12
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,051

    Re: What does it mean Call Back modifires in WinMain() function??

    Quote Originally Posted by mecheil.edwar View Post
    What I mean Exactly..
    when I start Debugging the Win32 Application I note the followings..
    All The WinAPI Functions as example :
    ATOM MyRegisterClass();
    LRESULT CALLBACK WndProc();
    INT_PTR CALLBACK About();
    Afraid I do not get you. These functions are not Win32 API entries. Those must be implemented somewhere in your code/libraries.

    All of these Functions are written in code as a prototype function , I mean when I declare any function I see as Example ; int Function1(...);
    This is the prototype , or declaration of function .. ok...

    So , When We write the win32 Application we declare as example wndProc function , and we write :
    LRESULT CALLBACK WndProc();
    Now when I start Debug , I see a pointer to every WinAPI Function I declared ..
    Again I don't follow you. Function declaration is not enough to make your program to work. There must be function body (implementation) somewhere in the code, otherwise the code won't compile.

    for example I can see the address of WndProc Function , the Address of About function and so , and so..
    When I asked about _stdcall , Igor and other colleagues said that , this is a standard call of function (between Operating system and my Application )
    My Question is , If I can see the address of each WinAPI Function .. can I go further more .. and see in more detail .. how this function is working?? or this is a low level layer between operating system and the code of program...
    in other words .. I think I can go in more details to see the as example the function WndProc() and see the code of this function and how it is working...
    You find WndProc body in the source code and set a breakpoint there. But I cannot see any relation to _stdcall. The latter is low level instruction to compiler how the call stack must be cleaned on return, nothing more than that. You never see anything low level in C/C++ code, you just declare it as _stdcall, and that's it. You can see these details in Disassembler mode where you can see CPU assembler instructions, but do you really think you need that?
    Best regards,
    Igor

  13. #13
    Join Date
    Jun 2012
    Location
    UAE
    Posts
    62

    Re: What does it mean Call Back modifires in WinMain() function??

    Thanks Igor So Much for your expalnations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center