Click to See Complete Forum and Search --> : Win32API: Help on DialogBoxParam function


Pradyumn
April 16th, 1999, 10:02 AM
I am writing a program using Win32API (not MFC). The following code had compiled in earlier versions of VC++, but in VC++5.0 it gives compile error, which I am not able to solve. The code is as follows (taken from Win32 Programming by Brent E. Rector and Joseph M. Newcomer, pg 782-783):


BOOL CALLBACK selectProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam);
LPPIZZA getPizzaSelection(HWND hwnd)
{
LPPIZZA pizza = (LPPIZZA)DialogBoxParam(GetWindowInstance(hwnd),
MAKEINTRESOURCE(DLG_SELECTPIZZA), hwnd, selectProc,
(LPARAM)PizzaTable);

return pizza;
}




The compile error on the first statement in the function is as follows:

D:\pradyumn\proj05\pizza.cpp(43) : error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'int (void *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(void)'

Basically, DIalogBoxParam function's fourth parameter is the name of the callback function for the dialog box. In this case, I am specifying selectProc whose forward declaration is also given above.

When I change the code of the getPizzaSelection function to the following:


DLGPROC x = selectProc;
LPPIZZA pizza = (LPPIZZA)DialogBoxParam(GetWindowInstance(hwnd),
MAKEINTRESOURCE(DLG_SELECTPIZZA), hwnd, x,
(LPARAM)PizzaTable);

return pizza;




Then the compile error is:

D:\pradyumn\proj05\pizza.cpp(41) : error C2440: 'initializing' : cannot convert from 'int (__stdcall *)(void *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(void)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

What do I need to do to solve this problem?

Paul McKenzie
April 16th, 1999, 10:21 AM
Try casting the selectProc to DLGPROC. Unlike "normal" variables, function pointers of one type cannot be assigned of another type in C++ without attempting to cast them.

I say "attempting" because if selectProc were a class member function (non-static), you could not cast it to a non-class member function type such as DLGPROC.

Regards,

Paul McKenzie

Mike Wild
April 27th, 1999, 02:05 AM
Try to use APIENTRY instead of CALLBACK

Mike