I have a (minor?) c++ problem
This might be a relatively simple question for some of you to answer. I''m creating a class that will represent my ''app'' in said class one of the member functions is the message handling callback function. yet, when i try to set this i get an error because the types are different.. i''ll give you some example code of what i''m trying to do, then the exact error.. hopefully someone knows what i''m doing wrong.. might be as simple as a needed cast but i dunno... here comes the code
class MyClass
{
public:
HRESULT Init();
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
}
LRESULT CALLBACK
MyClass::WndProcHWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
//blah blah, handle messages
}
HRESULT MyClass::Init()
{
WNDCLASS wc;
// the following line gives the error
wc.lpfnWndProc = WndProc;
}
here is the exact error:
error C2440: ''='' : cannot convert from ''long (__thiscall MyClass::*)(struct HWND__ *,unsigned int,unsigned int,long)'' to ''long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)''
There is no context in which this conversion is possible
I really hope somebody can help me here....
I did something like this, where you stick the win32 window stuff in a Class?...I fixed it by changing the Callback proc to outside of the class, but still in the same file so it was seperate - if you need any examples please e-mail me.
The problem is, is your classes msg handler method carries a this pointer. Thats why it cant do the conversion. Note:
(__thiscall MyClass::*)
you can go:
App *g_pApp;
fnWndProc(..)
{
return g_pApp->MsgProc(..);
}
App::App()
{
// constructor
g_pApp = this;
}
you make the WndProc global so it doesnt have a this pointer. Then have the WndProc call your applications procedure(App::MsgProc()). Look at D3DFramework for a more complete example.
ECKILLER
(__thiscall MyClass::*)
you can go:
App *g_pApp;
fnWndProc(..)
{
return g_pApp->MsgProc(..);
}
App::App()
{
// constructor
g_pApp = this;
}
you make the WndProc global so it doesnt have a this pointer. Then have the WndProc call your applications procedure(App::MsgProc()). Look at D3DFramework for a more complete example.
ECKILLER
ECKILLER
Well, when i first got this problem i tried to look into the d3dframe but thought that i only had the headers... when i realized the source was in the sdk i took a look... they do it exactly like you said, create a global pointer to the object and then a global WndProc that calls the objects WndProc...
thanks guys!!
AZ
thanks guys!!
AZ
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement