🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #500

Re: How to use SetWindowsHookEx?

#500
From: Darko Miletic
Date: Wed, 19 Mar 2008 14:29
25 lines
1957 bytes
amol wrote:
> 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) );
> }

You must cast the function pointer to HOOKPROC like this:

hook = SetWindowsHookEx(  WH_KEYBOARD
                         , reinterpret_cast<HOOKPROC>(KeyboardProc)
                         , hinstance
                         , 0U);
Technical Details
Message-ID: <47e1232c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <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
Date: Wed, 19 Mar 2008 11:29:00 -0300
From: Darko Miletic <kiklop@fibertel.com.ar>
Reply-To: Darko Miletic <kiklop@fibertel.com.ar>
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How to use SetWindowsHookEx?
References: <47e0a645$1@newsgroups.borland.com>
In-Reply-To: <47e0a645$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Antivirus: avast! (VPS 080319-0, 19/03/2008), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 200.49.157.165
Message-ID: <47e1232c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1205936940 200.49.157.165 (19 Mar 2008 07:29:00 -0700)
Lines: 27
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail