🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.ms.programmer
Article #806

Problems w/ GETMESSAGE Windows Hook

#806
From: Chris Newcomb
Date: Wed, 05 Dec 1990 07:42
111 lines
2839 bytes
I'm having problems using the WH_GETMESSAGE Windows hook in a DLL.  The hook
installs successfully and works correctly, but the system crashes and reboots
itself when the DLL exits.

I don't have any problems with the WH_CALLWNDPROC hook--replace all instances
of WH_GETMESSAGE with WH_CALLWNDPROC in the source below, and everything works.
The DLL consists of one source file (listed below) and the LIBENTRY.OBJ DLL
entry module provided with the SDK.  The source is compiled with:

cl -c -ASw -Gsw -Os


Here is the source file:

#include <windows.h>


void FAR PASCAL	GMHook(int, WORD, DWORD);	/*  Hook function	*/

FARPROC	lpNextGMHook;		/*  Next GETMESSAGE Hook function	*/


int FAR PASCAL
LibMain(hInstance, wDataSeg, nHeapSize, lpCmdLine)
HANDLE	hInstance;
WORD	wDataSeg;
WORD	nHeapSize;
LPSTR	lpCmdLine;
{
	/**
		I also tried passing in the return value of
			GetProcAddress(hInstance, "GMHook")
		instead of just passing in GMHook, but that didn't seem to make
		any difference.
	**/
	lpNextGMHook = SetWindowsHook(WH_GETMESSAGE, GMHook);
	return(TRUE);
}


void FAR PASCAL
WEP(nParameter)
int	nParameter;
{
	switch (nParameter) {

	    case WEP_FREE_DLL:
		/**
			We need to free all resources that the DLL is using,
			since we're dying but Windows isn't.

			This seems to be where all Hell breaks loose.
		**/
		UnhookWindowsHook(WH_GETMESSAGE, GMHook);
		return;

	    default:
		return;
	}
}


void FAR PASCAL
GMHook(nCode, wParam, lParam)
int	nCode;
WORD	wParam;
DWORD	lParam;
{
	/**
		Don't do anything with the message, just pass it on to the
		next guy.
	**/
	(void)DefHookProc(nCode, wParam, lParam, &lpNextGMHook);
}


/**
	Stub function to allow an application to load/run this DLL.
**/
void FAR PASCAL
foo()
{
}
------------------------------------------------------------------------------
Here is the .DEF file:

LIBRARY		HOOKLIB

DESCRIPTION	'Hook Test Library'

EXETYPE		WINDOWS

STUB		'WINSTUB.EXE'


CODE	PRELOAD FIXED
DATA	PRELOAD SINGLE FIXED		; Fixed data segment for the Hook


HEAPSIZE	0


EXPORTS
	foo		@1		; Stub function
	GMHook		@2		; Hook function
	WEP		@3	RESIDENTNAME
------------------------------------------------------------------------------

So...anybody got any ideas?  I'm stumped on this one.

Chris
Technical Details
Message-ID: <20294@oolong.la.locus.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!turnkey!orchard.la.locus.com!prodnet.la.locus.com!altair.la.locus.com!newcomb

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!turnkey!orchard.la.locus.com!prodnet.la.locus.com!altair.la.locus.com!newcomb
From: newcomb@altair.la.locus.com (Chris Newcomb)
Newsgroups: comp.windows.ms.programmer
Subject: Problems w/ GETMESSAGE Windows Hook
Keywords: Windows hook, DLL
Message-ID: <20294@oolong.la.locus.com>
Date: 5 Dec 90 07:42:54 GMT
Sender: news@locus.com
Lines: 111