Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetWindowsHookEx - code example

480 views
Skip to first unread message

ikinal

unread,
Jan 4, 2008, 3:27:26 PM1/4/08
to
\error C2664: 'SetWindowsHookExA' : cannot convert parameter 2 from
'HOOKPROC (int,WPARAM,LPARAM)' to 'HOOKPROC'


I'm trying to play with this function, and I can't
get the VC++ 7.0 compiler to accept the
callback func in the 2nd arg.

Here's the def:


HOOKPROC wireKeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
);

And here's the code:
SetWindowsHookEx (WH_KEYBOARD,wireKeyboardProc,NULL,0);


I've tried typecasts and typdefs, to no avail.

I tried passing a func with no args, but then
it said HOOKPROC(void) doesn't match
HOOKPROC. ???

Thanks for any help.
Ihor

Igor Tandetnik

unread,
Jan 4, 2008, 3:35:13 PM1/4/08
to
ikinal <iki...@ieee.org> wrote:
> \error C2664: 'SetWindowsHookExA' : cannot convert parameter 2 from
> 'HOOKPROC (int,WPARAM,LPARAM)' to 'HOOKPROC'
>
>
> I'm trying to play with this function, and I can't
> get the VC++ 7.0 compiler to accept the
> callback func in the 2nd arg.
>
> Here's the def:
>
>
> HOOKPROC wireKeyboardProc(
> int code, // hook code
> WPARAM wParam, // virtual-key code
> LPARAM lParam // keystroke-message information
> );

If you look at the documentation, the declaration of keyboard hook proc
should be

LRESULT CALLBACK wireKeyboardProc(
int code,
WPARAM wParam,
LPARAM lParam
);

It returns LRESULT, not HOOKPROC, and should have CALLBACK calling
convention.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


0 new messages