WORD expected in DialogBox()

This is a discussion on WORD expected in DialogBox() within the Windows Programming forums, part of the Platform Specific Boards category; I don't fully understand what the compiler means by saying it expects a WORD. I went through winprog.org, and some ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    416

    WORD expected in DialogBox()

    I don't fully understand what the compiler means by saying it expects a WORD. I went through winprog.org, and some other examples, and still don't quite understand what's happening.

    Code:
    case ID_FILE_DLG:
         {
               DLGTEMPLATE TEMP;
               TEMP.style = DS_CENTER | DS_MODALFRAME;
               TEMP.x = CW_USEDEFAULT;
               TEMP.y = CW_USEDEFAULT;
               TEMP.cx = 350;
               TEMP.cy = 250;
               TEMP.cdit = 1;
                            
               DLGITEMTEMPLATE Temp;
               Temp.style = WS_POPUP | WS_VISIBLE | BS_PUSHBUTTON;
               Temp.x = 25;
               Temp.y = 25;
               Temp.cx = 50;
               Temp.cy = 50;
               Temp.id = ID_DLGEND;
    						
               DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(TEMP), // <-- WORD expected here
    	         hwnd, DlgProc);
         }
         break;
    Error: `struct DLGTEMPLATE' used where a `WORD' was expected

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,263
    DialogBox expects a resource identifier (which is a WORD). If you are creating the dialog structures in memory yourself then DialogBoxIndirect is for you.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Changing it to DialogBoxIndirect() just gives me this error;

    cannot convert `DLGTEMPLATE' to `const DLGTEMPLATE*' for argument `2' to `int DialogBoxIndirectParamA(HINSTANCE__*, const DLGTEMPLATE*, HWND__*, BOOL (*)(HWND__*, UINT, WPARAM, LPARAM), LPARAM)'

    the code is the same as above, except with DialogBoxIndirect() instead of DialogBox(). What does it mean by a constant dialog template?

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,263
    That's because it's expecting a pointer to the structure as opposed to the value of it. In which case you use the "address of" operator &
    Code:
    DialogBoxIndirect(GetModuleHandle(NULL), &TEMP, hwnd, DlgProc);
    This MSDN Library page has an example right at the bottom that should help you. Creating templates yourself is pretty tricky.
    Last edited by SMurf; 08-22-2007 at 01:56 PM.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Thank you, it compiles now. It doesn't show up, but it compiles none the less. Thanks again.

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,263
    Try it with no controls (cdit = 0) first.
    The problem is that the function expects everything about the dialog to be in one long contigious area of memory. Notice you're declaring TEMP and Temp seperately: this doesn't necessarily mean that where one ends in memory the other begins.

    The example I pointed you towards demonstrates this by allocating 1024 bytes of memory and then using the various pointers to fill in the information. Alignment of the structures is also important; modern compilers tend to space them up to 16 bytes apart for performance reasons but the function expects a maximum of 4 bytes space.

    I can't help but feel you've jumped in at the deep end here...

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Now that you mentioned that, I think i might have too. I have some basic knowledge/understanding of windows programming, but dialogs are just getting confusing. I couldn't get it to work in a resource, so i thought i'd try it without a .rc file.

    Changing the cdit = 0 makes the menu bar dissapear, even if i change the CW_USEDEFAULT starting locations to something different. Is there a way to use 'new' and 'delete' to specify the memory for both the DLGTEMPLATE and DLGITEMTEMPLATE? Thanks for being understanding so far

    EDIT: I tried using the resource version again, and it would compile, but it says there is a syntax error on every line in the resource file. What am I missing? I followed the winprog.net example/tutorial to a 'T' and it still has the syntax errors.

    EDIT 2: Nevermind, did some searching on this site and got it all working. Thanks for your help smurf.
    Last edited by scwizzo; 08-23-2007 at 09:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 08:29 PM

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