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

Last change on this file since 7155 was 7155, checked in by phaller, 24 years ago

added PM hook

File size: 7.5 KB
Line 
1/* $Id: inituser32.cpp,v 1.6 2001-10-22 23:13:58 phaller 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/**************************************************************/
73#define PMKBDHK_MODULE "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
86void pmkbdhk_initialize(HAB _hab)
87{
88 APIRET rc;
89
90 if (pmkbdhk_installed == FALSE)
91 {
92 CHAR szBuf[260];
93
94 // load the DLL
95 rc = DosLoadModule(szBuf,
96 sizeof(szBuf),
97 PMKBDHK_MODULE,
98 &hmodPMKBDHK);
99 if (NO_ERROR != rc)
100 {
101 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed rc=%d\n",
102 _hab,
103 rc));
104
105 return;
106 }
107
108 // get the entry points
109 rc = DosQueryProcAddr(hmodPMKBDHK,
110 0,
111 PMKBDHK_HOOK_INIT,
112 (PFN*)&pfnHookInit);
113 if (NO_ERROR == rc)
114 rc = DosQueryProcAddr(hmodPMKBDHK,
115 0,
116 PMKBDHK_HOOK_TERM,
117 (PFN*)&pfnHookTerm);
118
119 if (NO_ERROR != rc)
120 {
121 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed importing functions, rc=%d\n",
122 _hab,
123 rc));
124
125 // free the DLL again
126 DosFreeModule(hmodPMKBDHK);
127 hmodPMKBDHK = NULLHANDLE;
128
129 return;
130 }
131
132 // now finally call the initializer function
133 pfnHookInit(_hab);
134
135 // OK, hook is armed
136 pmkbdhk_installed = TRUE;
137 }
138}
139
140void pmkbdhk_terminate(void)
141{
142 if (pmkbdhk_installed == TRUE)
143 {
144 // call the terminator function
145 pfnHookTerm();
146
147 // OK, hook is disarmed
148 pmkbdhk_installed = TRUE;
149 }
150
151 // unload the dll
152 if (NULLHANDLE != hmodPMKBDHK)
153 {
154 APIRET rc = DosFreeModule(hmodPMKBDHK);
155 if (NO_ERROR != rc)
156 {
157 dprintf(("USER32: pmkbdhk_terminate() failed rc=%d\n",
158 rc));
159
160 hmodPMKBDHK = NULLHANDLE;
161 }
162 }
163}
164
165
166/****************************************************************************/
167/* _DLL_InitTerm is the function that gets called by the operating system */
168/* loader when it loads and frees this DLL for each process that accesses */
169/* this DLL. However, it only gets called the first time the DLL is loaded */
170/* and the last time it is freed for a particular process. The system */
171/* linkage convention MUST be used because the operating system loader is */
172/* calling this function. */
173/****************************************************************************/
174ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag)
175{
176 size_t i;
177 APIRET rc;
178 ULONG version[2];
179
180 /*-------------------------------------------------------------------------*/
181 /* If ulFlag is zero then the DLL is being loaded so initialization should */
182 /* be performed. If ulFlag is 1 then the DLL is being freed so */
183 /* termination should be performed. */
184 /*-------------------------------------------------------------------------*/
185
186 switch (ulFlag) {
187 case 0 :
188 ParseLogStatusUSER32();
189
190 InitializeKernel32();
191 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
192
193 hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&user32_PEResTab,
194 USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
195 IMAGE_SUBSYSTEM_WINDOWS_GUI);
196 if(hInstanceUser32 == 0)
197 return 0UL;
198
199 dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
200
201 //SvL: Try to start communication with our message spy queue server
202 InitSpyQueue();
203
204 //SvL: Init win32 PM classes
205 //PH: initializes HAB!
206 if (FALSE == InitPM())
207 return 0UL;
208
209 // try to install the keyboard hook
210 pmkbdhk_initialize(hab);
211
212 //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
213 //CB: register internal classes
214 RegisterSystemClasses(hModule);
215
216 //CB: initialize PM monitor driver
217 MONITOR_Initialize(&MONITOR_PrimaryMonitor);
218
219 break;
220
221
222 case 1 :
223 if(hInstanceUser32) {
224 UnregisterLxDll(hInstanceUser32);
225 }
226 break;
227 default :
228 return 0UL;
229 }
230
231 /***********************************************************/
232 /* A non-zero value must be returned to indicate success. */
233 /***********************************************************/
234 return 1UL;
235}
236
237void APIENTRY cleanupUser32(ULONG ulReason)
238{
239 dprintf(("user32 exit\n"));
240
241 // try to unistall the keyboard hook
242 pmkbdhk_terminate();
243
244//SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
245//// RestoreCursor();
246 DestroyDesktopWindow();
247 Win32BaseWindow::DestroyAll();
248 UnregisterSystemClasses();
249 Win32WndClass::DestroyAll();
250 MONITOR_Finalize(&MONITOR_PrimaryMonitor);
251 SYSCOLOR_Save();
252 CloseSpyQueue();
253 dprintf(("user32 exit done\n"));
254}
255
Note: See TracBrowser for help on using the repository browser.