Article View: borland.public.cppbuilder.nativeapi
Article #507Re: How to use SetWindowsHookEx?
From: Ed Mulroy [TeamB]
Date: Wed, 19 Mar 2008 21:33
Date: Wed, 19 Mar 2008 21:33
48 lines
2344 bytes
2344 bytes
Better to not use a cast.
Instead:
What HOOKPROC is (from winuser.h)
typedef LRESULT (CALLBACK* HOOKPROC)(
int code,
WPARAM wParam,
LPARAM lParam);
Change your function to be
LRESULT CALLBACK KeyboardProc(int ncode, wParam wparam, lParam lparam)
so that it matches the type for which SetWindowsHookEx is supposed to
receive. You are passing an HINSTANCE to the wParam argument so cast that
calling parameter. Do not cast the whole function as that masks changes
made in any future edits and they can have devastating effects, for example:
forgetting to label the function as CALLBACK or __stdcall.
. Ed
> amol wrote in message
> news:47e0a645$1@newsgroups.borland.com...
>
> Hi there,
>
> I am getting following error messages while using SetWindowsHookEx:
>
> "cannot convert 'long (__stdcall *)(int,unsigned int,long)'
> to 'int(__stdcall *)()' "
>
> "Type mismatch in parameter 'lpfn' (wanted 'int(__stdcall *)()', got
> 'long(__stdcall *) (int,unsigned int,long)')"
>
>
> I am calling the "SetWindowsHookEx" as follow:
>
> hook = SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,hinstance,NULL);
> LRESULT CALLBACK KeyboardProc(int ncode,WPARAM wparam,LPARAM lparam)
> {
> return ( CallNextHookEx(hook,ncode,wparam,lparam) );
> }
>
> As per the documentation "KeyboardProc" should take three parameters, but
> it is giving me error.
> I am using C++ Builder 6.
Technical Details
Message-ID:
<47e186a4@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<47e0a645$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9f887c902c1804e1 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket> Newsgroups: borland.public.cppbuilder.nativeapi References: <47e0a645$1@newsgroups.borland.com> Subject: Re: How to use SetWindowsHookEx? Date: Wed, 19 Mar 2008 17:33:24 -0400 Lines: 50 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 71.77.48.179 Message-ID: <47e186a4@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1205962404 71.77.48.179 (19 Mar 2008 14:33:24 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail