Article View: borland.public.cppbuilder.nativeapi
Article #9482Global Message Hook Problem
From: Hugo Dias
Date: Mon, 05 Jul 2004 14:53
Date: Mon, 05 Jul 2004 14:53
84 lines
2820 bytes
2820 bytes
I'm trying to trap system message WM_RASDIALEVENT so i can detect when a RAS
dial attempt is started. I don't want to use time based check solutions.
I'm using a global hook to catch all windows messages. I don't know if
WM_RASDIALEVENT
will work but my problem for now it's not in there.
The problem that i'm actually facing it's that the hook only catches
messages for the caller application.
It doesn't trap messages from any other window. I've tried with
WH_CALLWNDPROC, WH_MSGFILTER
and WH_GETMESSAGE.
I had a similar problem with the same code when writing a Keyboard Hook.
WH_KEYBOARD didn't work
but WH_KEYBOARD_LL (not documented ? I found an example on the Net) solved
the problem.
This is the DLL code i'm using :
HOOK MsgHook;
HINSTANCE HInst;
extern "C" __declspec(dllexport) bool APIENTRY InstallHook(void);
extern "C" __declspec(dllexport) bool APIENTRY UnHook(void);
LRESULT CALLBACK Hook(int nCode, WPARAM wParam, LPARAM lParam);
bool APIENTRY InstallHook(void)
{
MsgHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)Hook, HInst, 0);
return (MsgHook != NULL);
}
bool APIENTRY UnHook(void)
{
if ( MsgHook == NULL )
return true;
if (UnhookWindowsHookEx(MsgHook))
{
MsgHook = NULL;
return true;
}
else
return false;
}
LRESULT CALLBACK Hook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
MSG *msg = (MSG *) lParam;
if (msg->message == WM_RASDIALEVENT)
{
int i = 0;
// Process Message
}
}
return CallNextHookEx(MsgHook, nCode, wParam, lParam);
}
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
HInst = hinst;
break;
case DLL_PROCESS_DETACH:
UnHook();
break;
}
return 1;
}
I would appreciate any help.
Thanks in advance,
Hugo Dias
Technical Details
Message-ID:
<40e96e45@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2561144f470ed1bd,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Hugo Dias" <synchron@nospam.synchron-systems.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Global Message Hook Problem Date: Mon, 5 Jul 2004 15:53:49 +0100 Lines: 87 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 83.144.132.174 Message-ID: <40e96e45@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1089039941 83.144.132.174 (5 Jul 2004 08:05:41 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail