function pointers (easy)
How do i declare a pointer to a function ?
In this case:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
Please help make my compiler stop bitching.
HRESULT (CALLBACK * Func)(HWMD, UINT, WPARAM, LPARAM);
"Func" is the variable name.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
"Func" is the variable name.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
quote:Original post by DrPizza
Use a typedef.
typedef LRESULT CALLBACK WndProcType(HWND, UINT, WPARAM, LPARAM);WndProcType* WndProcType_ptr;
That particular typedef already exists. It''s called WNDPROC.
I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
If you want to use the function pointer, you will need to make a typedef for it:
And where you want to declare you function:
And you set it like this:
If you were seting the function from inside a class, in the constructor you would need:
I hope that helped you
- err, the last signiture sucked bigtime!
typedef LRESULT CALLBACK WINDOW_PROC_CB(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);/* Thats not going to do anything but make declaring the function easyer */
And where you want to declare you function:
WINDOW_PROC_CB* WinProc = NULL;
And you set it like this:
WinProc = MyClassThingyWindowProc;/* Where MyClassThingyWindowProc is declared like this: LRESULT CALLBACK MyClassThingyWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);/* And MyClassThingyWindowProc() can be anything, like a function in a class
If you were seting the function from inside a class, in the constructor you would need:
// ...WinProc = this->SomeProc; // Where SomeProc will need the proper declereation stated above.
I hope that helped you
- err, the last signiture sucked bigtime!
What Jenova suggested seems to work.
I dont need to call the function directly. its used only when passing the wndproc parameter to the RegisterClass() function.
Its for an OpenGL/DirectX wrapper sorta thing btw.
Thanks all
I dont need to call the function directly. its used only when passing the wndproc parameter to the RegisterClass() function.
Its for an OpenGL/DirectX wrapper sorta thing btw.
Thanks all
...and don''t forget, you cannot set a function pointer to a class method. I hope in AfterMath''s example that "SomeProc" is just a WNDPROC member of that class, and not one of its methods.
Since a window proc must be a global when seting it (at least not in a class), you must have a dummy proc, or a re-router, as you will:
I might be of subject here :|
- err, the last signiture sucked bigtime!
TheClass* g_pClass = NULL;LRESULT CALLBACK WndProcDummy(HWND, UINT, WPARAM, LPARAM){ assert( g_pTheClass ); return ( g_pTheClass->WinProc(...) );}TheClass::TheClass(){ // ... g_pClass = this; /* This is IMPORTANT, I had a 1 week bug because of this :) */ / ...}TheClass::SomeFunctionThatCreatesAWindow(){ // ... wc.WinProc = WndProcDummy; // ...}
I might be of subject here :|
- err, the last signiture sucked bigtime!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement