Data invalid?

This is a discussion on Data invalid? within the Windows Programming forums, part of the Platform Specific Boards category; Hello, <edit> EDIT: Writing this made me realize that it could be the menu, so I removed it from dialog ...

  1. #1
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459

    Data invalid?

    Hello,

    <edit>EDIT: Writing this made me realize that it could be the menu, so I removed it from dialog #1001 and it worked, do I have to initialize menus or something too?

    I've tried with LoadMenu()/SetMenu() but I get the same error, my menu template is:
    Code:
    2001 MENUEX
    BEGIN
      POPUP "File", 0, 0, 0
      BEGIN
        MENUITEM "Config", 6002, 0, 0
        MENUITEM "", 0, 0|MFT_SEPARATOR, 0
        MENUITEM "Exit", 6001, 0, 0
      END
      POPUP "Help", 0, 0, 0
      BEGIN
        MENUITEM "About", 6004, 0, 0
      END
    END
    </edit>

    I'm creating a Win32 GUI application with MinGW. I have a dialog template in a resource, and I'm attempting to display it with DialogBox(), however I get a "13: The Data is invalid" error when I call DialogBox() trying to show the main dialog, but if I try to show another window it works (a window without dialog).

    The main code:
    Code:
    #include <windows.h>
    #include <commctrl.h>
    
    BOOL CALLBACK mainDialogProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
    void reportError(void);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        INITCOMMONCONTROLSEX commonControls;
        
        /* init the common controls */
        commonControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
        commonControls.dwICC = ICC_LISTVIEW_CLASSES | ICC_PROGRESS_CLASS;
            
        if(InitCommonControlsEx(&commonControls) != TRUE)
        {
            reportError();
            return 0;
        }
    
        if(DialogBox(hInstance, MAKEINTRESOURCE(1001), NULL, (DLGPROC) mainDialogProc) <= 0)
        {
            reportError();
            return 0;
        }
    
        
        return 0;
    }
    
    BOOL CALLBACK mainDialogProc(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch (msg)
        {
            case WM_INITDIALOG:
                MessageBox(0, "dialog ran", "hi", 0);
            return TRUE;
    	  
            default:
            return FALSE;
        }
    	
        return FALSE;
    }
    
    void reportError(void)
    {
        LPVOID lpMsgBuf;
        FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
                        NULL,
                        GetLastError(),
                        0,
                        (LPTSTR) &lpMsgBuf,
                        0,
                        NULL);
    
        MessageBox(NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONERROR);
    
        LocalFree(lpMsgBuf);
        return;
    }
    And the 2 dialog templates:
    Code:
    1001 DIALOGEX DISCARDABLE 6, 18, 374, 198
    STYLE WS_POPUP|DS_MODALFRAME|DS_3DLOOK|DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE
    CAPTION "pipsv"
    MENU 2001
    FONT 8, "MS Sans Serif", 0, 0, 1
    BEGIN
      CONTROL "Connection", 4001, "Button", BS_GROUPBOX, 248, 136, 124, 36
      CONTROL "", 4008, "msctls_progress32", PBS_SMOOTH|WS_BORDER, 8, 108, 88, 10
      CONTROL "test1", 4009, "Static", SS_CENTER|WS_GROUP, 8, 120, 88, 8
      CONTROL "test2", 4004, "Button", BS_GROUPBOX, 4, 136, 120, 60
      CONTROL "test3", 4005, "Static", WS_GROUP, 8, 148, 112, 8
       CONTROL "", 4010, "SysListView32", LVS_REPORT|LVS_SINGLESEL|LVS_AUTOARRANGE|WS_BORDER|WS_TABSTOP, 8, 16, 360, 88
    END
    
    1002 DIALOGEX DISCARDABLE 6, 18, 210, 142
    STYLE WS_POPUP|DS_MODALFRAME|DS_CONTEXTHELP|DS_3DLOOK|WS_CAPTION|WS_SYSMENU|WS_VISIBLE
    CAPTION "Dialog"
    FONT 8, "MS Sans Serif", 0, 0, 1
    BEGIN
      CONTROL "OK", IDOK, "Button", WS_TABSTOP, 160, 5, 45, 15
      CONTROL "Cancel", IDCANCEL, "Button", WS_TABSTOP, 160, 23, 45, 15
    END
    So in other words, when I try to show dialog #1001 I get the error, but it works fine with dialog #1002. I've initialized all the controls I've used - with InitCommonControlsEx() (I think)? The only difference between #1001 and #1002 is, 1001 has more controls and a menu... perhaps I haven't initialized all the controls I ask for?

    I compile with,
    Code:
    windres -o resource.o resource.rc
    gcc -W -Wall -ansi -pedantic -O2 -mwindows -D _WIN32_IE=0x0500 -o stuff resource.o stuff.c -lkernel32 -luser32 -lws2_32 -lgdi32 -lcomctl32
    Thanks in advance.
    Last edited by zacs7; 09-26-2007 at 02:36 AM.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    do I have to initialize menus or something too
    Yes.

    Your resource file:

    Code:
    #include <windows.h>
    1001 DIALOGEX DISCARDABLE 6, 18, 374, 198
    STYLE WS_POPUP|DS_MODALFRAME|DS_3DLOOK|DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE
    CAPTION "pipsv"
    FONT 8, "MS Sans Serif", 0, 0, 1
    BEGIN
      CONTROL "Connection", 4001, "Button", BS_GROUPBOX, 248, 136, 124, 36
      CONTROL "", 4008, "msctls_progress32", PBS_SMOOTH|WS_BORDER, 8, 108, 88, 10
      CONTROL "test1", 4009, "Static", SS_CENTER|WS_GROUP, 8, 120, 88, 8
      CONTROL "test2", 4004, "Button", BS_GROUPBOX, 4, 136, 120, 60
      CONTROL "test3", 4005, "Static", WS_GROUP, 8, 148, 112, 8
      CONTROL "", 4010, "SysListView32", LVS_REPORT|LVS_SINGLESEL|LVS_AUTOARRANGE|WS_BORDER|WS_TABSTOP, 8, 16, 360, 88
    END
    
    2001 MENU  
    BEGIN
        POPUP "Main"
        BEGIN
            MENUITEM "SubMain",                     2002
        END
        POPUP "SecondMain"
       BEGIN
           MENUITEM "SubSecondMain",               2003
       END
    END
    Menu loaded as follows:
    Code:
    HMENU hMenu;
    
    case WM_INITDIALOG:
    		hMenu =  LoadMenu(hInst, MAKEINTRESOURCE(2001));
     		SetMenu(hWndDlg,   hMenu);
            MessageBox(0, "dialog ran", "hi", 0);
            return TRUE;
    hInst is global

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If you want a separator in your menu then it's best to specify it as described for the MENUITEM resource definition statement, ie changing:
    Code:
    MENUITEM "", 0, 0|MFT_SEPARATOR, 0
    to
    Code:
    MENUITEM SEPARATOR
    in your menu resource will eliminate the error.

    You should really consider getting rid of all those magic numbers and replacing them with properly #defined labels in a resource header.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  4. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 07:43 AM
  5. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM

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