Article View: borland.public.cppbuilder.nativeapi
Article #8014Re: Help with Message hook
From: mike
Date: Tue, 07 Dec 2004 04:30
Date: Tue, 07 Dec 2004 04:30
153 lines
5378 bytes
5378 bytes
Remy,
Well the dll is loaded from a small test program I have. The Test program
calls the setup of the message hook in the following way.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( !SetupFullWindowsMsgFilterHook() )
{
ShowMessage( "Failed set Windows Message Hook" )
;
}
}
The code inside the Dll is defined as follows:
extern "C" {
__declspec(dllexport) bool __stdcall SetupFullWindowsMsgFilterHook( HWND
MessageMapWindow ) ;
}
HINSTANCE hInst
;
HWND hWindowForMessages
;
HHOOK hMsgFilterHook ;
int WINAPI DllEntryPoint( HINSTANCE hinst, unsigned long reason, void* )
{
hInst = hinst
;
return 1 ;
}
bool __stdcall SetupFullWindowsMsgFilterHook( HWND MessageMapWindow )
{
hMsgFilterHook = SetWindowsHookEx( WH_MSGFILTER ,
(HOOKPROC)MessageProc,
hInst,
0) ;
hWindowForMessages = MessageMapWindow ;
}
LRESULT CALLBACK MessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
AnsiString DataVal
;
if ( nCode < 0 )
{
return CallNextHookEx (hMsgFilterHook, nCode,
wParam, lParam);
}
// this is only here to see if any messages are being seen inside the hook
DataVal = "Filter Hook "
;
COPYDATASTRUCT cds = {0}
;
cds.dwData = 0x4D696B65;
cds.cbData = DataVal.Length()
;
cds.lpData = DataVal.c_str()
;
::SendMessage( hWindowForMessages , WM_COPYDATA, 0,
reinterpret_cast<LPARAM>( &cds ) ) ;
if ( nCode == MSGF_MENU)
{
DataVal = "Filter Hook -- Menu
Message" ;
COPYDATASTRUCT cds = {0}
;
cds.dwData = 0x4D696B65;
cds.cbData = DataVal.Length()
;
cds.lpData = DataVal.c_str()
;
::SendMessage( hWindowForMessages , WM_COPYDATA,
0, reinterpret_cast<LPARAM>( &cds ) ) ;
CWPSTRUCT *cwpsParam = (CWPSTRUCT *) lParam;
if( cwpsParam->message == WM_MENUSELECT )
{
DataVal = "Filter Hook -- Menu
Select Message" ;
COPYDATASTRUCT cds = {0}
;
cds.dwData = 0x4D696B65;
cds.cbData = DataVal.Length()
;
cds.lpData = DataVal.c_str()
;
::SendMessage( hWindowForMessages , WM_COPYDATA,
0, reinterpret_cast<LPARAM>( &cds ) ) ;
}
}
return CallNextHookEx (hMsgFilterHook, nCode, wParam,
lParam);
}
That is all the code. I have traced the DLL and it appears the call to the
DLL is working fine as I see it and the hMsgFilterHook gets an address
assigned. But no messages are received within the hook procedure.
I really appreciate you helping me with this.
Thanks
Mike
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41b50838@newsgroups.borland.com...
>
> "mike" <mfbrowne@earthlink.net> wrote in message
> news:41b4fee6@newsgroups.borland.com...
>
> > Here is the calling procedure:
>
> Where exactly is that being called from? Please alwasy show complete code
> that can actually be compiled when needed.
>
> > So as I said I am not receiving any messages pumped through this
> > hook. What I am trying to accomplish is to find out what menu was
> > opened in any application running in the system.I am actually surprised
> > I am not getting anything through the hook.
>
> Sounds like the hook is not set up correctly.
>
>
> Gambit
>
>
Technical Details
Message-ID:
<41b531bf$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!transit.nntp.hccnet.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41b2766c$1@newsgroups.borland.com> <41b412e1$1@newsgroups.borland.com> <41b4fee6@newsgroups.borland.com> <41b50838@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,21323583e8de481a X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "mike" <mfbrowne@earthlink.net> Newsgroups: borland.public.cppbuilder.nativeapi References: <41b2766c$1@newsgroups.borland.com> <41b412e1$1@newsgroups.borland.com> <41b4fee6@newsgroups.borland.com> <41b50838@newsgroups.borland.com> Subject: Re: Help with Message hook Date: Mon, 6 Dec 2004 23:30:55 -0500 Lines: 155 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 68.204.189.169 Message-ID: <41b531bf$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1102393791 68.204.189.169 (6 Dec 2004 20:29:51 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!transit.nntp.hccnet.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail