LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam); // Additional Message Information
LRESULT CALLBACK (lptrWindProc*) (HWND,UINT,WPARAM,LPARAM); //Function Pointer to the windows Message Lopp
Win32 Function Pointers
OK, this is my second attempt at this !
I have declaread a global function pointer to my windows message loop. Ihave done this so that I can pass this as a parameter to my windows Objects as they are created.
I am getting errors when I try to compile (MSVC 6)
The declaration is as below;
Then in my applications main loop I have
lptrWindProc = (&WndProc);
Is there a better way of passing the WndProc to a windows class as I make it, and why if I am declared as above do I get the following errors ?
e:\CODING_PROJECTS\Win32_OGLBase\Win32_OGLBase.cpp(35) : error C2059: syntax error : ''(''
119) : error C2065: ''lptrWindProc'' : undeclared identifier
e:\CODING_PROJECTS\Win32_OGLBase\Win32_OGLBase.cpp(119) : error C2440: ''='' : cannot convert from ''long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
I have tried putting the CALLBACK in brackets but that doesn''t help. Can anyone shed some light onto this, I am going mad slowly trying to resolve what should be a simple problem !
Thanks,
Bp.
, when I want a new window I am
Not sure if it will help, but try declaring the variable lptrWindProc first.
VOID* lptrWindProc = NULL;
I should probably be working now...
VOID* lptrWindProc = NULL;
I should probably be working now...
Nope, just get a different error message..
e:\CODING_PROJECTS\Win32_OGLBase\Win32_OGLBase.cpp(37) : error C2165: ''left-side modifier'' : cannot modify pointers to data
e:\CODING_PROJECTS\Win32_OGLBase\Win32_OGLBase.cpp(37) : error C2165: ''left-side modifier'' : cannot modify pointers to data
I''m not sure, but try it without the & sign. I think functions are already pointers. I''m not sure about this. I think i read it in a C++ book a while back when I was in school.
Try it and see.
Try it and see.
Your Code should be...
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
///HANDLE MESSAGE
}
Then when you create your object from WNDCLASSEX.
WNDCLASSEX winclass;
Just refer to the name of the CALLBACK function.. like this
winclass.lpfnWndProc = WindowProc;
That''s it..
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
///HANDLE MESSAGE
}
Then when you create your object from WNDCLASSEX.
WNDCLASSEX winclass;
Just refer to the name of the CALLBACK function.. like this
winclass.lpfnWndProc = WindowProc;
That''s it..
Thanks AP, but I was doing that.
I was trying to create a fnction pointer so that I could pass it as a parameter to my CWndClass:CWndClass(...) and create an instance of any window that referred to the Main Message Function.
I have it fixed now, I needed the CALLBACK inside the bracket as well. Sometimes Trial and Error will save the day
If anyone has any comments on how I am doing this, then please tell me. I don''t know if it''s the best way, but it is the way I think it should be done.
Bp.
I was trying to create a fnction pointer so that I could pass it as a parameter to my CWndClass:CWndClass(...) and create an instance of any window that referred to the Main Message Function.
I have it fixed now, I needed the CALLBACK inside the bracket as well. Sometimes Trial and Error will save the day
If anyone has any comments on how I am doing this, then please tell me. I don''t know if it''s the best way, but it is the way I think it should be done.
Bp.
A generalised, global function pointer looks like this:
return-type (*pointer-name)(argument-type, argument-type);
You can have the argument names in there too, if you want, but it doesn''t make any difference.
Then, a function name on it''s own is a pointer. So when you do MyFunction(), you''re saying ''jump to the code pointed to by MyFunction.'' In the same way, you can create a function pointer of your own (as shown above) and do MyFunctionPointer() - although stylistically, you should probably do (MyFunctionPointer)().
Later, you get into Functors.. and then the party really gets fun...
return-type (*pointer-name)(argument-type, argument-type);
You can have the argument names in there too, if you want, but it doesn''t make any difference.
Then, a function name on it''s own is a pointer. So when you do MyFunction(), you''re saying ''jump to the code pointed to by MyFunction.'' In the same way, you can create a function pointer of your own (as shown above) and do MyFunctionPointer() - although stylistically, you should probably do (MyFunctionPointer)().
Later, you get into Functors.. and then the party really gets fun...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement