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

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

PF: migrate windows fonts

File size: 10.8 KB
Line 
1/* $Id: inituser32.cpp,v 1.15 2003-10-20 17:18:30 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#define INCL_WINSHELLDATA
32#include <os2wrap.h> //Odin32 OS/2 api wrappers
33#include <stdlib.h>
34#include <stdio.h>
35#include <string.h>
36#include <odin.h>
37#include <misc.h> /*PLF Wed 98-03-18 23:18:29*/
38#include <win32type.h>
39#include <win32api.h>
40#include <winconst.h>
41#include <odinlx.h>
42#include <spy.h>
43#include <monitor.h>
44#include "pmwindow.h"
45#include "win32wdesktop.h"
46#include "win32wndhandle.h"
47#include "syscolor.h"
48#include "initterm.h"
49#include <exitlist.h>
50#include <initdll.h>
51#include <stats.h>
52
53#define DBG_LOCALLOG DBG_initterm
54#include "dbglocal.h"
55
56/*-------------------------------------------------------------------*/
57/* A clean up routine registered with DosExitList must be used if */
58/* runtime calls are required and the runtime is dynamically linked. */
59/* This will guarantee that this clean up routine is run before the */
60/* library DLL is terminated. */
61/*-------------------------------------------------------------------*/
62static void APIENTRY cleanup(ULONG reason);
63
64extern "C" {
65 //Win32 resource table (produced by wrc)
66 extern DWORD user32_PEResTab;
67}
68DWORD hInstanceUser32 = 0;
69
70extern INT __cdecl wsnprintfA(LPSTR,UINT,LPCSTR,...);
71
72/**************************************************************/
73/* Try to load the Presentation Manager Keyboard Hook module. */
74/* If this fails, some hotkeys may not arrive properly at the */
75/* targetted window, but no more harmful things will happen. */
76/**************************************************************/
77static char PMKBDHK_MODULE[16] = "PMKBDHK";
78#define PMKBDHK_HOOK_INIT "hookInit"
79#define PMKBDHK_HOOK_TERM "hookKill"
80
81static BOOL pmkbdhk_installed = FALSE;
82static HMODULE hmodPMKBDHK;
83
84static PVOID (*APIENTRY pfnHookInit)(HAB);
85static BOOL (*APIENTRY pfnHookTerm)(void);
86
87// defined initialized in pmwindow.cpp: InitPM()
88extern HAB hab;
89
90//******************************************************************************
91//******************************************************************************
92void WIN32API SetCustomPMHookDll(LPSTR pszKbdDllName)
93{
94 strcpy(PMKBDHK_MODULE, pszKbdDllName);
95}
96
97#define FONTSDIRECTORY "Fonts"
98#define REGPATH "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
99
100//******************************************************************************
101//******************************************************************************
102void MigrateWindowsFonts()
103{
104 HKEY hkFonts,hkOS2Fonts;
105 char buffer[512];
106 UINT len = GetWindowsDirectoryA( NULL, 0 );
107
108 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGPATH ,0, KEY_ALL_ACCESS, &hkFonts) == 0)
109 {
110 DWORD dwIndex, dwType;
111 char subKeyName[255], dataArray[512];
112 DWORD sizeOfSubKeyName = 254, sizeOfDataArray = 511;
113
114 // loop over all values of the current key
115 for (dwIndex=0;
116 RegEnumValueA(hkFonts, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, &dwType ,(LPBYTE)dataArray, &sizeOfDataArray) != ERROR_NO_MORE_ITEMS_W;
117 ++dwIndex, sizeOfSubKeyName = 254, sizeOfDataArray = 511)
118 {
119 //Check OS/2 INI profile for font entry
120 if (!PrfQueryProfileString(HINI_PROFILE, "PM_Fonts", dataArray,
121 NULL, (PVOID)subKeyName, (LONG)sizeof(subKeyName)))
122 {
123 HDIR hdirFindHandle = HDIR_CREATE;
124 FILEFINDBUF3 FindBuffer = {0};
125 ULONG ulResultBufLen = sizeof(FILEFINDBUF3);
126 ULONG ulFindCount = 1;
127 APIRET rc = NO_ERROR;
128
129 dprintf(("Migrating font %s to OS/2",dataArray));
130
131 GetWindowsDirectoryA( buffer, len + 1 );
132 wsnprintfA( buffer, sizeof(buffer), "%s\\%s\\%s", buffer, FONTSDIRECTORY, dataArray );
133
134 rc = DosFindFirst( buffer, &hdirFindHandle, FILE_NORMAL,&FindBuffer, ulResultBufLen, &ulFindCount, FIL_STANDARD);
135
136 //Check that file actaully exist
137 if ( rc == NO_ERROR && !(FindBuffer.attrFile & FILE_DIRECTORY))
138 {
139 PrfWriteProfileString(HINI_PROFILE,"PM_Fonts",dataArray, buffer);
140 DosFindClose(hdirFindHandle);
141 }
142 }
143 }
144 RegCloseKey(hkFonts);
145 }
146}
147
148//******************************************************************************
149//******************************************************************************
150void pmkbdhk_initialize(HAB _hab)
151{
152 APIRET rc;
153
154 if ((pmkbdhk_installed == FALSE) && PMKBDHK_MODULE[0])
155 {
156 CHAR szBuf[260];
157
158 // load the DLL
159 rc = DosLoadModule(szBuf,
160 sizeof(szBuf),
161 PMKBDHK_MODULE,
162 &hmodPMKBDHK);
163 if (NO_ERROR != rc)
164 {
165 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed rc=%d\n",
166 _hab,
167 rc));
168
169 return;
170 }
171
172 // get the entry points
173 rc = DosQueryProcAddr(hmodPMKBDHK,
174 0,
175 PMKBDHK_HOOK_INIT,
176 (PFN*)&pfnHookInit);
177 if (NO_ERROR == rc)
178 rc = DosQueryProcAddr(hmodPMKBDHK,
179 0,
180 PMKBDHK_HOOK_TERM,
181 (PFN*)&pfnHookTerm);
182
183 if (NO_ERROR != rc)
184 {
185 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed importing functions, rc=%d\n",
186 _hab,
187 rc));
188
189 // free the DLL again
190 DosFreeModule(hmodPMKBDHK);
191 hmodPMKBDHK = NULLHANDLE;
192
193 return;
194 }
195
196 // now finally call the initializer function
197 pfnHookInit(_hab);
198
199 // OK, hook is armed
200 pmkbdhk_installed = TRUE;
201 }
202}
203//******************************************************************************
204//******************************************************************************
205void pmkbdhk_terminate(void)
206{
207 if (pmkbdhk_installed == TRUE)
208 {
209 // call the terminator function
210 pfnHookTerm();
211
212 // OK, hook is disarmed
213 pmkbdhk_installed = FALSE;
214 }
215
216 // unload the dll
217 if (NULLHANDLE != hmodPMKBDHK)
218 {
219 APIRET rc = DosFreeModule(hmodPMKBDHK);
220 if (NO_ERROR != rc)
221 {
222 dprintf(("USER32: pmkbdhk_terminate() failed rc=%d\n",
223 rc));
224
225 hmodPMKBDHK = NULLHANDLE;
226 }
227 }
228}
229/****************************************************************************/
230/* _DLL_InitTerm is the function that gets called by the operating system */
231/* loader when it loads and frees this DLL for each process that accesses */
232/* this DLL. However, it only gets called the first time the DLL is loaded */
233/* and the last time it is freed for a particular process. The system */
234/* linkage convention MUST be used because the operating system loader is */
235/* calling this function. */
236/****************************************************************************/
237ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag)
238{
239 size_t i;
240 APIRET rc;
241 ULONG version[2];
242
243 /*-------------------------------------------------------------------------*/
244 /* If ulFlag is zero then the DLL is being loaded so initialization should */
245 /* be performed. If ulFlag is 1 then the DLL is being freed so */
246 /* termination should be performed. */
247 /*-------------------------------------------------------------------------*/
248
249 switch (ulFlag) {
250 case 0 :
251 ParseLogStatusUSER32();
252
253 InitializeKernel32();
254 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
255
256 hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&user32_PEResTab,
257 USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
258 IMAGE_SUBSYSTEM_WINDOWS_GUI);
259 if(hInstanceUser32 == 0)
260 return 0UL;
261
262 dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
263
264 //SvL: Try to start communication with our message spy queue server
265 InitSpyQueue();
266
267 //SvL: Init win32 PM classes
268 //PH: initializes HAB!
269 if (FALSE == InitPM())
270 return 0UL;
271
272 // try to install the keyboard hook
273 pmkbdhk_initialize(hab);
274
275 InitializeWindowHandles();
276
277 //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
278 //CB: register internal classes
279 RegisterSystemClasses(hModule);
280
281 //CB: initialize PM monitor driver
282 MONITOR_Initialize(&MONITOR_PrimaryMonitor);
283
284 //PF: migrate windows fonts
285 MigrateWindowsFonts();
286
287 break;
288
289
290 case 1 :
291 if(hInstanceUser32) {
292 UnregisterLxDll(hInstanceUser32);
293 }
294 break;
295 default :
296 return 0UL;
297 }
298
299 /***********************************************************/
300 /* A non-zero value must be returned to indicate success. */
301 /***********************************************************/
302 return 1UL;
303}
304//******************************************************************************
305//******************************************************************************
306void APIENTRY cleanupUser32(ULONG ulReason)
307{
308 dprintf(("user32 exit\n"));
309
310 // try to unistall the keyboard hook
311 pmkbdhk_terminate();
312
313//SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
314//// RestoreCursor();
315
316 //Destroy CD notification window
317 WinDestroyWindow(hwndCD);
318 DestroyDesktopWindow();
319 Win32BaseWindow::DestroyAll();
320 UnregisterSystemClasses();
321 Win32WndClass::DestroyAll();
322 MONITOR_Finalize(&MONITOR_PrimaryMonitor);
323 SYSCOLOR_Save();
324 CloseSpyQueue();
325 FinalizeWindowHandles();
326 STATS_DumpStatsUSER32();
327 dprintf(("user32 exit done\n"));
328}
329//******************************************************************************
330//******************************************************************************
Note: See TracBrowser for help on using the repository browser.