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

Last change on this file since 10256 was 10256, checked in by sandervl, 22 years ago

Updates

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