|
-
May 8th, 2006, 08:26 PM
#1
Thread Starter
Addicted Member
[RESOLVED]Callback Type Problem
First off, I'm a newbie C++ coder, so I'm sorry if what I'm asking is obvious, but searching has given me no solution. I'm trying to write a simple window class with the message handler passed by the class user, so I define a member variable as "LRESULT(*)(HWND, UINT, WPARAM, LPARAM)", which is supposed to be the function pointer. Then I assign the passed value(same type) to this member, which results in the error: "invalid conversion from `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)' to `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'". I read that it could be caused by the function address being that of a non-static member function, but I've tried both a normal function and a member, and both result in the same error.
Here's the code that concerns this problem(it's scattered around a few files, but that's unimportant I think all are linked by inclusion):
PHP Code:
typedef LRESULT(*grCallbackWndProc)(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK MessageHandler(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
grErrorCode grWindow::Create(HINSTANCE hInstance,
grCallbackWndProc WndProc,
LPSTR sTitle,
int iWidth,
int iHeight,
int iStyle) {
if (0 == WndProc) {
//This line gives the error.
mWndProc = &MessageHandler;
} else {
mWndProc = WndProc;
}
//Rest of code that compiles fine.
}
This is using the GCC compiler.
Thanks for any insight.
Last edited by Max_aka_NOBODY; May 9th, 2006 at 07:59 AM.
Please, put a checkmark (  ) or the word [RESOLVED] in your topic title if it was resolved, and rate the person who resolved it.
-
May 8th, 2006, 11:23 PM
#2
Re: Callback Type Problem
To save you a serious headache, you cannot use a non-static member function as the window procedure, because of the hidden "this" pointer that needs to be passed to each member function.
Otherwise, if you're not using a member function, your code looks fine. Maybe try adding CALLBACK after LRESULT in your typdef -- CALLBACK is defined as __stdcall while the default calling convention is 'cdecl.' This might be the problem.
edit: I think you put the calling convention inside the parentheses -- ie,
typedef LRESULT( CALLBACK *grCallbackWndProc)(HWND, UINT, WPARAM, LPARAM);
but I'm not sure
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
May 9th, 2006, 04:43 AM
#3
Re: Callback Type Problem
sunburnt's answer is correct.
But also, there's no need for the typedef. windows.h already contains one by the name of WNDPROC.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 9th, 2006, 06:47 AM
#4
Thread Starter
Addicted Member
Re: Callback Type Problem
Thanks a lot. Works like a charm.
Please, put a checkmark (  ) or the word [RESOLVED] in your topic title if it was resolved, and rate the person who resolved it.
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
|