|
-
April 16th, 1999, 10:02 AM
#1
Win32API: Help on DialogBoxParam function
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?
-
April 16th, 1999, 10:21 AM
#2
Re: Win32API: Help on DialogBoxParam function
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
-
April 27th, 1999, 02:05 AM
#3
Re: Win32API: Help on DialogBoxParam function
Try to use APIENTRY instead of CALLBACK
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|