🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: SetWindowsHookEx & WH_KEYBOARD

#14547
From: MWP
Date: Mon, 11 Aug 2003 10:54
59 lines
2649 bytes
Fixed.... i created the DLL with VC++6.


>Hi all...
>
>I have made a DLL that uses SetWindowsHookEx(WH_KEYBOARD....) to get keypreesses.
>The problem is its not global... it only works while the app using the DLL is in focus.
>
>How do i fix this?
>
>Code for the DLL is below.
>
>Thanks.
>
>//---------------------------------------------------------------------------
>#include <vcl.h>
>#include <windows.h>
>#pragma hdrstop
>//---------------------------------------------------------------------------
>#define EXTC extern "C"
>#define DLLOPT __export WINAPI
>
>HHOOK hhook;
>HINSTANCE hinste;
>
>DWORD lastkey;
>DWORD lastlp;
>
>//---------------------------------------------------------------------------
>#pragma argsused
>int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
>{
>	hinste = hinst;
>	return 1;
>}
>//---------------------------------------------------------------------------
>LRESULT KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
>{
>	lastkey = wParam;
>	lastlp = lParam;
>
>	return CallNextHookEx(hhook, nCode, wParam, lParam);
>}
>//---------------------------------------------------------------------------
>EXTC void DLLOPT install_hook()
>{
>	hhook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, hinste, 0);
>}
>//---------------------------------------------------------------------------
>EXTC void DLLOPT last_key(DWORD *key, DWORD *lp)
>{
>	*key = lastkey;
>	*lp = lastlp;
>}
>//---------------------------------------------------------------------------
>
>
>
Technical Details
Message-ID: <3f3775dd$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!diablo.voicenet.com!news.astraweb.com!news-small.astraweb.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3f374896@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,65d385623513ec23
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-11 04:00:29 PST
From: "MWP" <mwp@overclockers.com.au>
Sender: "MWP" <mwp@overclockers.com.au>
Reply-To: "MWP" <mwp@overclockers.com.au>
Subject: Re: SetWindowsHookEx & WH_KEYBOARD
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 203.16.214.242 203.16.214.242    
X-Forwarded-For: unknown, 150.101.76.105
References:  <3f374896@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3f3775dd$1@newsgroups.borland.com>
Date: 11 Aug 2003 03:54:21 -0700
X-Trace: newsgroups.borland.com 1060599261 207.105.83.65 (11 Aug 2003 03:54:21 -0700)
Lines: 60
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border3.nntp.aus1.giganews.com!nntp.giganews.com!diablo.voicenet.com!news.astraweb.com!news-small.astraweb.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail