Two Return Types???

This is a discussion on Two Return Types??? within the Windows Programming forums, part of the Platform Specific Boards category; I've got what I think is a pretty basic question regarding Win32 programming. I've recently started learning it and noticed ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    4

    Two Return Types???

    I've got what I think is a pretty basic question regarding Win32 programming. I've recently started learning it and noticed something I'd never seen before; what appeared to be two return types. On the tutorial I'm reading, the WinMain function is defined as
    Code:
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
    Now I'm in no way an expert programmer, but that has me completely baffled as to how it works. I know it returns an int and is called WinMain, but what's the deal with the WINAPI? Another location I noticed this "double return" type function is in
    Code:
    LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    Now I have a decent understanding of what each function can do, but again what is with these functions? Again, this is probably a n00b question, but any help is greatly appreciated

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    WINAPI and CALLBACK are not return types. They describe the type of function. CALLBACKs are bascially what is called when a window needs something done to it.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    4
    Erm...Sorry I don't quite understand what you mean by the "type of function". I googled for "C++ Function Types" and found quite a few pages dealing with templates. Are these in fact templates? I'm really not familiar with templates, although I will readily read up on them if need be.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    No, its nothing to do with C++ and everything to do with window's programming.

    Its kinda like a modifier that lets the compiler know to do certain things.

    Much in the same way using PASCAL can change the way the function handles parameters

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    4
    I see thanks that clarified it a bit more

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I'll have to let someone with more win programming experience give some more details though

  7. #7
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    a more correct name for "function type" is calling convention.

    No, its nothing to do with C++ and everything to do with window's programming.
    That's not entirely true. Windows uses it a lot, but they use it because C++ allows it. The calling conventions that a function can take are part of c++. If I remember correctly, WINAPI is #defined as __stdcall.

    For more information, look up calling conventions

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thanks for correcting the term. I've done win32 programming as C code so its not really based off of c++.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > The calling conventions that a function can take are part of c++.
    Standard C++ has only one such thing, and that's extern "C" for calling C code.
    Everything else is down to implementation specifics for your compiler.
    So it would be an extension for win32 compilers at best.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    So it isn't a standard thing...curse VC++ for having me think otherwise!!!

    here's a question then: Is it not common for calling conventions to be implimented?

  11. #11
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    They're called calling conventions because the "compiler community" has agreed upon the definitions of those conventions (thus making them a convention).

    The calling convention is just one component of a compiler's application binary interface, or ABI. The ABI defines memory layout of user-defined and built-in data types, v-table layout, function calling conventions, exception handling conventions, global naming, and several other object code conventions. The ABI defines all the practical components of running on real hardware that the standard does not define since the standard is meant to be machine agnostic.

    All compilers implement some consistent method for calling and returning from functions. Most make use of pre-defined conventions like "cdecl" and "stdcall". Most C/C++ compilers also support, as a "language extension", the ability for the developer to specifiy which calling convention to use.

    Even though the standard doesn't go into defining calling convetions, it's a "logistical reality" that most programmers have to deal with unless you're writting pure standard C/C++ code.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is it ok like that?
    By ExDHaos in forum C++ Programming
    Replies: 8
    Last Post: 05-23-2009, 09:02 AM
  2. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  3. C++ FTP class won't work
    By lord mazdak in forum C++ Programming
    Replies: 8
    Last Post: 12-18-2005, 06:57 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

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