Thread: DialogBox Argument Invalid?

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    137

    DialogBox Argument Invalid?

    Hi, i searched around for all the dialog box problems on forum, and none seem to help me.

    The error i get is this:
    argument of type `BOOL (CppWnd:(HWND__*, UINT, WPARAM, LPARAM)' does not match `BOOL (*)(HWND__*, UINT, WPARAM, LPARAM)'

    I'm sure that my program being in a really big Class, there are some variable losses or something going on. Heres the code:

    In my OnCommand Function, which is called from the Case WM_COMMAND, i have this incase someone presses "about"

    Code:
    if((nID == IDD_ABOUTBOX) && (uNotifyCode == BN_CLICKED)){
           DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUTBOX), hAppWnd, (DLGPROC)AboutDlgProc);
         }
    hAppWnd is my HWND... IDD_ABOUTBOX HAS been defined.

    I've declared the prototype in my header file too. Same way. My AboutDlgProc function is CppWnd::AboutDlgProc, and is BOOL CALLBACK.

    However, i keep getting this error, i've tried every possible thing, but it doesnt work.

    I think perhaps, the UINT Message, wParam and lParam are getting lost because I dont have DialogBox() inside the WndProc function under WM_COMMAND. But i am not sure.

    ABOUT CODE:
    Code:
    BOOL CALLBACK CppWnd::AboutDlgProc(HWND hAppWnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
                        EndDialog(hAppWnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hAppWnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }
    Last edited by execute; 04-22-2006 at 07:53 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You can't use a normal class member function as a window procedure because it's of the wrong type (not a window or dialog procedure) - make it a static class member function instead.

    Also, the return type for DialogProc is INT_PTR now.

    Welcome to the boards.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    Thx.

    Ok, i used static, and it worked.

    I also changed any mention of "BOOL" to INT_PTR.

    EDIT: ok works ^^.
    There was a small linker error, cuz i accidently removed CppWnd:: from in front of where AboutProc was defined.
    There was an error also where i entered wrong ID for the Resource, so it wasnt loading.

    Thanks for your help :O
    Last edited by execute; 04-22-2006 at 09:26 PM.

  4. #4
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    im surprised you aren't having troubles with the procedure.

    Usualy when you wrap procedures in classes you have to have 2... one statical and one non-statical

    Code:
    static LRESULT CALLBACK StaticWndProc(HWND hwnd, UINT msg,
    								WPARAM wParam, LPARAM lParam)
    	{
    		if ( msg == WM_CREATE )
    		{
    			SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG)(LONG_PTR)((CREATESTRUCT *)lParam)->lpCreateParams );
    		}
    		
    		CppApplication *targetApp = (CppApplication*)(LONG_PTR)GetWindowLongPtr( hwnd, GWLP_USERDATA );
    
    		if ( targetApp )
    		{
    			return targetApp->WndProc( hwnd, msg, wParam, lParam );
    		}
    
    		return DefWindowProc( hwnd, msg, wParam, lParam ); 
    	}
    this what the statical procedure looks. When you create the window/dialog you have to pass a pointer of your class as the LPARAM.

    On the WM_CREATE Message you can set the pointer as the window long pointer and then retrieve it everytime you get a new message.

    Works pretty well, I hope this helps.
    My Website
    010000110010101100101011
    Add Color To Your Code!

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    Mine is definately not that complex. And it works fine on a bunch of computers :X.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM
  5. Flood of errors when include .h
    By erik2004 in forum C++ Programming
    Replies: 14
    Last Post: 12-07-2002, 07:37 AM