source: trunk/src/user32/inituser32.cpp@ 7622

Last change on this file since 7622 was 7622, checked in by sandervl, 24 years ago

Added function to override name of the PM keyboard hook dll

File size: 8.5 KB
Line 
1/* $Id: inituser32.cpp,v 1.8 2001-12-13 12:24:42 sandervl Exp $ */
2/*
3 * USER32 DLL entry point
4 *
5 * Copyright 1998 Sander van Leeuwen
6 * Copyright 1998 Peter Fitzsimmons
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13/*-------------------------------------------------------------*/
14/* INITERM.C -- Source for a custom dynamic link library */
15/* initialization and termination (_DLL_InitTerm) */
16/* function. */
17/* */
18/* When called to perform initialization, this sample function */
19/* gets storage for an array of integers, and initializes its */
20/* elements with random integers. At termination time, it */
21/* frees the array. Substitute your own special processing. */
22/*-------------------------------------------------------------*/
23
24
25/* Include files */
26#define INCL_DOSMODULEMGR
27#define INCL_DOSPROCESS
28#define INCL_DOSSEMAPHORES
29#define INCL_DOSMISC
30#define INCL_DOSERRORS
31#include <os2wrap.h> //Odin32 OS/2 api wrappers
32#include <stdlib.h>
33#include <stdio.h>
34#include <string.h>
35#include <odin.h>
36#include <misc.h> /*PLF Wed 98-03-18 23:18:29*/
37#include <win32type.h>
38#include <win32api.h>
39#include <winconst.h>
40#include <odinlx.h>
41#include <spy.h>
42#include <monitor.h>
43#include "pmwindow.h"
44#include "win32wdesktop.h"
45#include "syscolor.h"
46#include "initterm.h"
47#include <exitlist.h>
48#include <initdll.h>
49
50#define DBG_LOCALLOG DBG_initterm
51#include "dbglocal.h"
52
53/*-------------------------------------------------------------------*/
54/* A clean up routine registered with DosExitList must be used if */
55/* runtime calls are required and the runtime is dynamically linked. */
56/* This will guarantee that this clean up routine is run before the */
57/* library DLL is terminated. */
58/*-------------------------------------------------------------------*/
59static void APIENTRY cleanup(ULONG reason);
60
61extern "C" {
62 //Win32 resource table (produced by wrc)
63 extern DWORD user32_PEResTab;
64}
65DWORD hInstanceUser32 = 0;
66
67
68/**************************************************************/
69/* Try to load the Presentation Manager Keyboard Hook module. */
70/* If this fails, some hotkeys may not arrive properly at the */
71/* targetted window, but no more harmful things will happen. */
72/**************************************************************/
73static char PMKBDHK_MODULE[16] = "PMKBDHK";
74#define PMKBDHK_HOOK_INIT "hookInit"
75#define PMKBDHK_HOOK_TERM "hookKill"
76
77static BOOL pmkbdhk_installed = FALSE;
78static HMODULE hmodPMKBDHK;
79
80static PVOID (*APIENTRY pfnHookInit)(HAB);
81static BOOL (*APIENTRY pfnHookTerm)(void);
82
83// defined initialized in pmwindow.cpp: InitPM()
84extern HAB hab;
85
86//******************************************************************************
87//******************************************************************************
88void WIN32API SetCustomPMHookDll(LPSTR pszKbdDllName)
89{
90 strcpy(PMKBDHK_MODULE, pszKbdDllName);
91}
92//******************************************************************************
93//******************************************************************************
94void pmkbdhk_initialize(HAB _hab)
95{
96 APIRET rc;
97
98 if (pmkbdhk_installed == FALSE)
99 {
100 CHAR szBuf[260];
101
102 // load the DLL
103 rc = DosLoadModule(szBuf,
104 sizeof(szBuf),
105 PMKBDHK_MODULE,
106 &hmodPMKBDHK);
107 if (NO_ERROR != rc)
108 {
109 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed rc=%d\n",
110 _hab,
111 rc));
112
113 return;
114 }
115
116 // get the entry points
117 rc = DosQueryProcAddr(hmodPMKBDHK,
118 0,
119 PMKBDHK_HOOK_INIT,
120 (PFN*)&pfnHookInit);
121 if (NO_ERROR == rc)
122 rc = DosQueryProcAddr(hmodPMKBDHK,
123 0,
124 PMKBDHK_HOOK_TERM,
125 (PFN*)&pfnHookTerm);
126
127 if (NO_ERROR != rc)
128 {
129 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed importing functions, rc=%d\n",
130 _hab,
131 rc));
132
133 // free the DLL again
134 DosFreeModule(hmodPMKBDHK);
135 hmodPMKBDHK = NULLHANDLE;
136
137 return;
138 }
139
140 // now finally call the initializer function
141 pfnHookInit(_hab);
142
143 // OK, hook is armed
144 pmkbdhk_installed = TRUE;
145 }
146}
147//******************************************************************************
148//******************************************************************************
149void pmkbdhk_terminate(void)
150{
151 if (pmkbdhk_installed == TRUE)
152 {
153 // call the terminator function
154 pfnHookTerm();
155
156 // OK, hook is disarmed
157 pmkbdhk_installed = TRUE;
158 }
159
160 // unload the dll
161 if (NULLHANDLE != hmodPMKBDHK)
162 {
163 APIRET rc = DosFreeModule(hmodPMKBDHK);
164 if (NO_ERROR != rc)
165 {
166 dprintf(("USER32: pmkbdhk_terminate() failed rc=%d\n",
167 rc));
168
169 hmodPMKBDHK = NULLHANDLE;
170 }
171 }
172}
173/****************************************************************************/
174/* _DLL_InitTerm is the function that gets called by the operating system */
175/* loader when it loads and frees this DLL for each process that accesses */
176/* this DLL. However, it only gets called the first time the DLL is loaded */
177/* and the last time it is freed for a particular process. The system */
178/* linkage convention MUST be used because the operating system loader is */
179/* calling this function. */
180/****************************************************************************/
181ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag)
182{
183 size_t i;
184 APIRET rc;
185 ULONG version[2];
186
187 /*-------------------------------------------------------------------------*/
188 /* If ulFlag is zero then the DLL is being loaded so initialization should */
189 /* be performed. If ulFlag is 1 then the DLL is being freed so */
190 /* termination should be performed. */
191 /*-------------------------------------------------------------------------*/
192
193 switch (ulFlag) {
194 case 0 :
195 ParseLogStatusUSER32();
196
197 InitializeKernel32();
198 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
199
200 hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&user32_PEResTab,
201 USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
202 IMAGE_SUBSYSTEM_WINDOWS_GUI);
203 if(hInstanceUser32 == 0)
204 return 0UL;
205
206 dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
207
208 //SvL: Try to start communication with our message spy queue server
209 InitSpyQueue();
210
211 //SvL: Init win32 PM classes
212 //PH: initializes HAB!
213 if (FALSE == InitPM())
214 return 0UL;
215
216 // try to install the keyboard hook
217 pmkbdhk_initialize(hab);
218
219 //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
220 //CB: register internal classes
221 RegisterSystemClasses(hModule);
222
223 //CB: initialize PM monitor driver
224 MONITOR_Initialize(&MONITOR_PrimaryMonitor);
225
226 break;
227
228
229 case 1 :
230 if(hInstanceUser32) {
231 UnregisterLxDll(hInstanceUser32);
232 }
233 break;
234 default :
235 return 0UL;
236 }
237
238 /***********************************************************/
239 /* A non-zero value must be returned to indicate success. */
240 /***********************************************************/
241 return 1UL;
242}
243//******************************************************************************
244//******************************************************************************
245void APIENTRY cleanupUser32(ULONG ulReason)
246{
247 dprintf(("user32 exit\n"));
248
249 // try to unistall the keyboard hook
250 pmkbdhk_terminate();
251
252//SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
253//// RestoreCursor();
254
255 //Destroy CD notification window
256 WinDestroyWindow(hwndCD);
257 DestroyDesktopWindow();
258 Win32BaseWindow::DestroyAll();
259 UnregisterSystemClasses();
260 Win32WndClass::DestroyAll();
261 MONITOR_Finalize(&MONITOR_PrimaryMonitor);
262 SYSCOLOR_Save();
263 CloseSpyQueue();
264 dprintf(("user32 exit done\n"));
265}
266//******************************************************************************
267//******************************************************************************
Note: See TracBrowser for help on using the repository browser.