🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #238

Re: Help with WinSetHook?

#238
From: Dan Ford
Date: Tue, 04 Aug 1992 18:51
55 lines
2532 bytes
grumpy@jpradley.jpr.com (Jeff Markel) writes:
> 
>Are there any good examples around of how to use hooks?  I've looked in several
>PM programming books and there was nary a mention of hook procedures, let alone
>how to write or use one.
> 
>If anyone could post a short example, or point me toward one, I'd be grateful...
> 			Thanks...
> 
>                         Jeff Markel
> 

  Well, I don't have a complete example to give you (our use of hooks is
too involved to make it a good example).  However, I can give you a small
skeleton--and a word of warning about what I believe is a bug we found in
OS/2.

Below is a skeleton hook function designed to filter out application
specific messages during system modal loops.

BOOL EXPENTRY DspHookProc (HAB hab, PQMSG pqmsg, USHORT msgf)
{
	pqmsg->msg = (pqmsg->msg & 0x0000FFFF);	// see bug note below
	if (pqmsg->msg >= WM_USER) {
		// do something with message
		return TRUE; 	// msg is not passed on
	} else
		return FALSE;	// msg is passed on
}

The statement that registers the hook function looks like this:

	fRet = WinSetHook (hab, hmq, HK_MSGFILTER,
				(PFN)DspHookProc, NULLHANDLE);

Bug note:
	IBM changed the size of the message ID from a USHORT in OS/2 1.x to
a ULONG in OS/2 2.0.  As a result of this, the data structure for a QMSG got
correspondingly larger.  They forgot somewhere to make the correct assignment
when passing messages on to hook procedures.  Because I found that the msg
field of the pqmsg parameter in the hook procedure had bogus data in the
upper two bytes of the message ID.  This is the reason for the first
statement in the hook proc, where I AND the value 0x0000FFFF with the
message ID to clear out the upper 16 bits.  This gives the correct message
values, and everything seems to work correctly.  

	Does anybody know if this is a bug, or do those bits mean something
now?

Good luck,

Dan Ford
Cardiology Business Unit
Hewlett-Packard
McMinnville, OR
Technical Details
Message-ID: <1992Aug04.185149.27639@hpmcaa.mcm.hp.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!darwin.sura.net!mips!sdd.hp.com!hp-cv!hp-pcd!hpmcaa!hpmcaa!ford
References: <1992Jul29.174651.1879@jpradley.jpr.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!gatech!darwin.sura.net!mips!sdd.hp.com!hp-cv!hp-pcd!hpmcaa!hpmcaa!ford
From: ford@hpmcaa (Dan Ford)
Subject: Re: Help with WinSetHook?
Message-ID: <1992Aug04.185149.27639@hpmcaa.mcm.hp.com>
Sender: news@hpmcaa.mcm.hp.com (News Administrator)
Nntp-Posting-Host: hpmcaa.mcm.hp.com
Organization: HP Cardiology Business Unit - McMinnville, OR
X-Newsreader: Tin 1.1 PL4
References: <1992Jul29.174651.1879@jpradley.jpr.com>
Date: Tue, 04 Aug 1992 18:51:49 GMT
Lines: 55