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

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

stats dump function renamed

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