Results 1 to 10 of 10

Thread: problem with vc++

  1. #1
    Member Contributor
    Join Date
    Jul 2001
    Location
    Czech Republic
    Posts
    78

    problem with vc++

    I have some problems with "summoning" of a dialog box. I have done this:

    BOOL CALLBACK MyDlgProc(HWND, UINT, WPARAM, LPARAM);

    and then in program trying to use it:

    DialogBox(hInstance, "MyDlg", hwnd, MyDlgProc);

    the compiler is all the time complaining about this:

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

    PLEEASE HELP!
    Thanks in advance

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: problem with vc++

    www.codeguru.com or www.codeproject.com is
    a good place to get help on this type of problems.

    Mikael

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Augsburg, Germany
    Posts
    334

    Re: problem with vc++

    Originally posted by Platinum:
    I have some problems with "summoning" of a dialog box. I have done this:

    BOOL CALLBACK MyDlgProc(HWND, UINT, WPARAM, LPARAM);

    and then in program trying to use it:

    DialogBox(hInstance, "MyDlg", hwnd, MyDlgProc);

    the compiler is all the time complaining about this:

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

    PLEEASE HELP!
    Thanks in advance
    Seems like it's some mixed C and C++ calling conventions here. C has the calling convention __stdcall, but C++ uses __cdecl *. You could try to use

    extern "C" BOOL CALLBACK MyDlgProc(HWND, UINT, WPARAM, LPARAM) to force the __stdcall calling convention.

    Kilam.


    [This message has been edited by Kilam Malik (edited 07-26-2001).]

  4. #4
    Member Contributor
    Join Date
    Jul 2001
    Location
    Czech Republic
    Posts
    78

    Re: problem with vc++

    Thanks for those links, but I didn't find any solution there. Nor the C/C++ naming conventions didn't work. I think it is a problem with my compiler. I will get some Service Pack.

    Thank you very much anyway.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: problem with vc++

    It look's like the CALLBACK is wrong declared somehow, have you included all the correct headers ?

    Try to replace CALLBACK with __stdcall in the declaration and see if that helps maybe ?

    Mikael

  6. #6
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: problem with vc++

    Just letting you know I know _nothing_ about MFC or Win32 programming, but in your error, surely the DialogBox function is expecting a function pointer of the form int (*) (void), regardless of the calling convention? Since your function pointer is of the type int (*) (void *, unsigned int, unsigned int, long) it will never match, irrespective of the calling convention. Or is there some mystery about Windows programming that I don't know about?

    Hope that helps.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,595

    Re: problem with vc++

    Hi again !

    If you don't have STRICT #defined then DLGPROC is declared as having no arguments (void), if you have STRICT #define, then DLGPROC is declared as:

    typedef BOOL (CALLBACK* DLGPROC)(HWND, UINT, WPARAM, LPARAM);

    Mikael

  8. #8
    Member Contributor
    Join Date
    Jul 2001
    Location
    Czech Republic
    Posts
    78

    Re: problem with vc++

    Thanks for that #define STRICT advice. You were right, it was wrongly defined. Now I don't get those error messages anymore. But the program still does not work. i don't know why. I even tried installing the newest service pack, changing resources, rewriting the program, but still nothing. The DialogBox function keeps on returning with -1.

  9. #9
    Junior Member Newbie
    Join Date
    Jan 2001
    Location
    london ont canada
    Posts
    25

    Re: problem with vc++

    judging by the original code, the thing that sticks out to me is the "MyDlg" argument to the DialogBox function - is that a reference to a resource id number?
    here's a short example of getting a dialog right:

    Code :
    //function prototype
    BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
     
    // the winmain code starts here
     
    // hInstance - winmain instance
    // IDD_OPTIONS - resource id (make sure to use MAKEINTRESOURCE
    // NULL - window owner (no parent)
    // DlgProc - the function to call (cast to DLGPROC)
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_OPTIONS), NULL, (DLGPROC)DlgProc)
     
    // end winmain
     
     
    // dlgproc implentation
    BOOL CALLBACK DlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
    {
       switch(msg)
       {
       case WM_INITDIALOG:
          // do whatever
          break;
       case WM_COMMAND:
          switch( LOWORD(wParam) )
          {
          case IDOK:   // if you have IDOK
             EndDialog(hDlg, 1) // will return one
             break;
          case IDCANCEL:   // if you have IDCANCEL
             EndDialog(hDlg, 0) // will return zero
             break;
          }
       }
       return 0;
    }
    if you start off with a stripped down dialog box (ie. with only an ok and cancel button) the dialog should pop up.

    things that may make it screw it up (for example) are slider controls, they require additional Create"XControl" functions.

  10. #10
    Member Contributor
    Join Date
    Jul 2001
    Location
    Czech Republic
    Posts
    78

    Re: problem with vc++

    thanks dallas, finally WORKS!

Similar Threads

  1. Replies: 1
    Last Post: 09-23-2016, 02:24 PM
  2. Shading problem? (pyglet-problem?, my problem?)
    By H2OBrain in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-03-2009, 08:31 AM
  3. Replies: 4
    Last Post: 09-27-2004, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean