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

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

Updates

File size: 8.0 KB
Line 
1/* $Id: inituser32.cpp,v 1.18 2003-11-14 13:44:10 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#define INCL_GPI
33#define INCL_WINERRORS
34#include <os2wrap.h> //Odin32 OS/2 api wrappers
35#include <stdlib.h>
36#include <stdio.h>
37#include <string.h>
38#include <odin.h>
39#include <misc.h> /*PLF Wed 98-03-18 23:18:29*/
40#include <win32type.h>
41#include <win32api.h>
42#include <winconst.h>
43#include <odinlx.h>
44#include <spy.h>
45#include <monitor.h>
46#include <kbdhook.h>
47#include "pmwindow.h"
48#include "win32wdesktop.h"
49#include "win32wndhandle.h"
50#include "syscolor.h"
51#include "initterm.h"
52#include <exitlist.h>
53#include <initdll.h>
54#include <stats.h>
55
56#define DBG_LOCALLOG DBG_initterm
57#include "dbglocal.h"
58
59/*-------------------------------------------------------------------*/
60/* A clean up routine registered with DosExitList must be used if */
61/* runtime calls are required and the runtime is dynamically linked. */
62/* This will guarantee that this clean up routine is run before the */
63/* library DLL is terminated. */
64/*-------------------------------------------------------------------*/
65static void APIENTRY cleanup(ULONG reason);
66
67extern "C" {
68 //Win32 resource table (produced by wrc)
69 extern DWORD user32_PEResTab;
70}
71DWORD hInstanceUser32 = 0;
72
73extern INT __cdecl wsnprintfA(LPSTR,UINT,LPCSTR,...);
74
75//******************************************************************************
76#define FONTSDIRECTORY "Fonts"
77#define REGPATH "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
78//******************************************************************************
79void MigrateWindowsFonts()
80{
81 HKEY hkFonts,hkOS2Fonts;
82 char buffer[512];
83 UINT len;
84
85 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGPATH ,0, KEY_ALL_ACCESS, &hkFonts) == 0)
86 {
87 DWORD dwIndex, dwType;
88 char subKeyName[255], dataArray[512];
89 DWORD sizeOfSubKeyName = 254, sizeOfDataArray = 511;
90
91 // loop over all values of the current key
92 for (dwIndex=0;
93 RegEnumValueA(hkFonts, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, &dwType ,(LPBYTE)dataArray, &sizeOfDataArray) != ERROR_NO_MORE_ITEMS_W;
94 ++dwIndex, sizeOfSubKeyName = 254, sizeOfDataArray = 511)
95 {
96 HDIR hdirFindHandle = HDIR_CREATE;
97 FILEFINDBUF3 FindBuffer = {0};
98 ULONG ulResultBufLen = sizeof(FILEFINDBUF3);
99 ULONG ulFindCount = 1, ret;
100 APIRET rc = NO_ERROR;
101
102 GetWindowsDirectoryA( buffer, sizeof(buffer) );
103 wsnprintfA( buffer, sizeof(buffer), "%s\\%s\\%s", buffer, FONTSDIRECTORY, dataArray );
104
105 rc = DosFindFirst( buffer, &hdirFindHandle, FILE_NORMAL,&FindBuffer, ulResultBufLen, &ulFindCount, FIL_STANDARD);
106 //Check that file actaully exist
107 if ( rc == NO_ERROR && !(FindBuffer.attrFile & FILE_DIRECTORY))
108 {
109 //Check OS/2 INI profile for font entry
110 len = PrfQueryProfileString(HINI_PROFILE, "PM_Fonts", dataArray,
111 NULL, (PVOID)subKeyName, (LONG)sizeof(subKeyName));
112
113 //If it doesn't exist OR if it's outdated
114 if(len == 0 || strcmp(subKeyName, buffer))
115 {
116 dprintf(("Migrating font %s to OS/2",dataArray));
117
118 ret = GpiLoadFonts(0, buffer);
119 if(ret == FALSE) {
120 dprintf(("GpiLoadFonts %s failed with %x", buffer, WinGetLastError(0)));
121 }
122 }
123 }
124 DosFindClose(hdirFindHandle);
125 }
126 RegCloseKey(hkFonts);
127 }
128}
129/****************************************************************************/
130/* _DLL_InitTerm is the function that gets called by the operating system */
131/* loader when it loads and frees this DLL for each process that accesses */
132/* this DLL. However, it only gets called the first time the DLL is loaded */
133/* and the last time it is freed for a particular process. The system */
134/* linkage convention MUST be used because the operating system loader is */
135/* calling this function. */
136/****************************************************************************/
137ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag)
138{
139 size_t i;
140 APIRET rc;
141 ULONG version[2];
142
143 /*-------------------------------------------------------------------------*/
144 /* If ulFlag is zero then the DLL is being loaded so initialization should */
145 /* be performed. If ulFlag is 1 then the DLL is being freed so */
146 /* termination should be performed. */
147 /*-------------------------------------------------------------------------*/
148
149 switch (ulFlag) {
150 case 0 :
151 ParseLogStatusUSER32();
152
153 InitializeKernel32();
154 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
155
156 hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&user32_PEResTab,
157 USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
158 IMAGE_SUBSYSTEM_WINDOWS_GUI);
159 if(hInstanceUser32 == 0)
160 return 0UL;
161
162 dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
163
164 //SvL: Try to start communication with our message spy queue server
165 InitSpyQueue();
166
167 //SvL: Init win32 PM classes
168 //PH: initializes HAB!
169 if (FALSE == InitPM())
170 return 0UL;
171
172 InitializeWindowHandles();
173
174 //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
175 //CB: register internal classes
176 RegisterSystemClasses(hModule);
177
178 //CB: initialize PM monitor driver
179 MONITOR_Initialize(&MONITOR_PrimaryMonitor);
180
181 //PF: migrate windows fonts
182 MigrateWindowsFonts();
183
184 break;
185
186
187 case 1 :
188 if(hInstanceUser32) {
189 UnregisterLxDll(hInstanceUser32);
190 }
191 break;
192 default :
193 return 0UL;
194 }
195
196 /***********************************************************/
197 /* A non-zero value must be returned to indicate success. */
198 /***********************************************************/
199 return 1UL;
200}
201//******************************************************************************
202//******************************************************************************
203void APIENTRY cleanupUser32(ULONG ulReason)
204{
205 dprintf(("user32 exit\n"));
206
207//SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
208//// RestoreCursor();
209
210 //Destroy CD notification window
211 WinDestroyWindow(hwndCD);
212 DestroyDesktopWindow();
213 Win32BaseWindow::DestroyAll();
214 UnregisterSystemClasses();
215 Win32WndClass::DestroyAll();
216 MONITOR_Finalize(&MONITOR_PrimaryMonitor);
217 SYSCOLOR_Save();
218 CloseSpyQueue();
219 FinalizeWindowHandles();
220 STATS_DumpStatsUSER32();
221 dprintf(("user32 exit done\n"));
222}
223//******************************************************************************
224//******************************************************************************
Note: See TracBrowser for help on using the repository browser.