bool vs BOOL

This is a discussion on bool vs BOOL within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to convert my console app. to a Windows app. but I am a little bit confused as ...

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Question bool vs BOOL

    I am trying to convert my console app. to a Windows app. but I am a little bit confused as to the difference between these two lines:

    Code:
      BOOL CALLBACK InputProc(HWND, UINT, WPARAM, LPARAM);
    
      bool CALLBACK InputProc(HWND, UINT, WPARAM, LPARAM);
    The first line everything complies without errors but the second line gives the following error. (Obviously that the 4th param. is wrong but I dont understand why!)

    error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'bool (struct HWND__ *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(struct HWND__*,unsigned int,unsigned int,long)'

    Why are bool and BOOL different in this example?

    I am currently running MSV C on an XP pro machine.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    bool is a built-in C++ variable type. Like long, short, double etc.
    BOOL, on the other hand is typedefed to int in <windows.h>.

    In MSVC, sizeof(bool) == 1, while sizeof(BOOL) == sizeof(int) == 4. Therefore these types are not interchangeable. Also, a bool can only hold true or false while a BOOL has traditionally been used to hold arbitary int values, where 0 is false and any other value true. Also in the past, BOOL has been used to pass pointers and other other data types.

    Microsoft API prototypes will generally not use the bool datatype as it is not available in C.

    Note that the correct prototype for a dialog box procedure is now:
    Code:
    INT_PTR CALLBACK DialogProc(
        HWND hwndDlg,
        UINT uMsg,
        WPARAM wParam,
        LPARAM lParam
    );
    This is beacause a BOOL can not hold a pointer in Win64.

    >> (Obviously that the 4th param. is wrong but I dont understand why!) <<

    The error is not saying that the fourth argument of the function prototype is wrong, it is saying the the fourth argument to DialogBoxParam() is wrong. The fourth argument is the function pointer and the function pointer that you are passing does not match.
    Last edited by anonytmouse; 04-05-2004 at 11:50 PM.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    8
    Do it this way:
    Code:
    LRESULT CALLBACK InputProc(HWND, UINT, WPARAM, LPARAM);
    DialogBox(hInstance, dialog_name, parent, (DLGPROC) InputProc);
    That should work :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing params between managed c++ and unmanaged c++
    By cechen in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2009, 08:46 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM
  5. Need Help With an RPG Style Game
    By JayDog in forum Game Programming
    Replies: 6
    Last Post: 03-30-2003, 08:43 PM

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