PDA

View Full Version : problem with vc++



Platinum
07-25-2001, 10:22 PM
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

mikael_aronsson
07-25-2001, 10:42 PM
www.codeguru.com (http://www.codeguru.com) or www.codeproject.com (http://www.codeproject.com) is
a good place to get help on this type of problems.

Mikael

Kilam Malik
07-26-2001, 02:18 AM
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).]

Platinum
07-26-2001, 06:01 PM
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.

mikael_aronsson
07-26-2001, 10:33 PM
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

ffish
07-26-2001, 11:04 PM
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.

mikael_aronsson
07-27-2001, 01:55 AM
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

Platinum
08-08-2001, 07:22 PM
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. http://www.opengl.org/discussion_boards/ubb/mad.gif

dallas
08-09-2001, 11:45 AM
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:




//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.

Platinum
08-12-2001, 10:21 PM
thanks dallas, finally WORKS!
http://www.opengl.org/discussion_boards/ubb/biggrin.gif