| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Hooks |
Hi Johan
May-05-95, Johan Siegers wrote to All:
JS> Can anyone post a working example, of how to set a hook ?
JS> My application is created by WinCreateStdWindow().
JS> I tried both a hook in the current HMQ as a system hook, both after
JS> examples in Borlands Help (with a HK_INPUT hook). All by
JS> hookprocedure does is a single beep. I DO get the beeps, but my
JS> applications crashes in an access violation.
JS> Should I perhaps set the hook at a very specific point ?
The hook procedure must reside in a DLL. The procedure will be called in
different process contexts, and DLLs are loaded into the memory area that
is present in all process contexts.
Here is a DLL I made to monitor keyboard and mouse activity by hooking into
the system queue.
SCRDLL.C (for BCOS2 1.0)
qp
/\
#define INCL_DOS
#define INCL_WIN
#include
#include "scrdll.h"
ULONG ulActivity;
HMODULE hmDll;
#pragma argsused
static int APIENTRY DllInputHook (HAB hab, QMSG *Qmsg, ULONG fs)
{
switch (Qmsg->msg)
{
case WM_CHAR:
case WM_MOUSEMOVE:
case WM_BUTTON1DOWN:
case WM_BUTTON2DOWN:
case WM_BUTTON3DOWN:
ulActivity++;
break;
}
return FALSE;
}
/* should be called from application at startup */
BOOL EXPENTRY DllInit (HAB hab)
{
BOOL rc;
rc = DosQueryModuleHandle ("SCRDLL", &hmDll);
if (rc)
return FALSE;
rc = WinSetHook (hab, NULLHANDLE, HK_INPUT, DllInputHook, hmDll);
if (!rc)
return FALSE;
ulActivity = 0;
return TRUE;
}
/* returns the amount of activity since last time */
ULONG EXPENTRY DllGetActivity (VOID)
{
ULONG activity = ulActivity;
ulActivity = 0;
return activity;
}
/* should be called from the application before terminating */
BOOL EXPENTRY DllDeinit (HAB hab)
{
BOOL rc;
rc = WinReleaseHook (hab, NULLHANDLE, HK_INPUT, DllInputHook, hmDll);
if (!rc)
return FALSE;
return TRUE;
}
\/
db
Regards, Karl
--- FleetStreet 1.03 #356
* Origin: NightCall Point (2:237/10.105)SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407 SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809 @PATH: 237/10 15 9 236/9 235/50 240/5500 24/999 2/777 105/42 712/515 711/808 @PATH: 711/809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.