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

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

Mikael

Originally posted by Platinum:
[b]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[/b]

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).]

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.

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

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.

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

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.

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.

thanks dallas, finally WORKS!