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

Last change on this file since 21303 was 21303, checked in by ydario, 16 years ago

User32 updates.

File size: 8.2 KB
Line 
1/* $Id: inituser32.cpp,v 1.19 2004-05-03 12:09:01 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 STATS_InitializeUSER32 ();
152
153 ParseLogStatusUSER32();
154
155 InitializeKernel32();
156 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
157
158 hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&user32_PEResTab,
159 USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
160 IMAGE_SUBSYSTEM_WINDOWS_GUI);
161 if(hInstanceUser32 == 0)
162 return 0UL;
163
164 dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
165
166 //SvL: Try to start communication with our message spy queue server
167 InitSpyQueue();
168
169 //SvL: Init win32 PM classes
170 //PH: initializes HAB!
171 if (FALSE == InitPM())
172 return 0UL;
173
174 InitializeWindowHandles();
175
176 //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
177 //CB: register internal classes
178 RegisterSystemClasses(hModule);
179
180 //CB: initialize PM monitor driver
181 MONITOR_Initialize(&MONITOR_PrimaryMonitor);
182
183 //PF: migrate windows fonts
184 MigrateWindowsFonts();
185
186 InitClipboardFormats();
187
188 RasEntry (RAS_EVENT_User32InitComplete, &hInstanceUser32, sizeof (hInstanceUser32));
189
190 break;
191
192
193 case 1 :
194 if(hInstanceUser32) {
195 UnregisterLxDll(hInstanceUser32);
196 }
197 STATS_UninitializeUSER32 ();
198 break;
199 default :
200 return 0UL;
201 }
202
203 /***********************************************************/
204 /* A non-zero value must be returned to indicate success. */
205 /***********************************************************/
206 return 1UL;
207}
208//******************************************************************************
209//******************************************************************************
210void APIENTRY cleanupUser32(ULONG ulReason)
211{
212 dprintf(("user32 exit\n"));
213
214//SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
215//// RestoreCursor();
216
217 //Destroy CD notification window
218 WinDestroyWindow(hwndCD);
219 DestroyDesktopWindow();
220 Win32BaseWindow::DestroyAll();
221 UnregisterSystemClasses();
222 Win32WndClass::DestroyAll();
223 MONITOR_Finalize(&MONITOR_PrimaryMonitor);
224 SYSCOLOR_Save();
225 CloseSpyQueue();
226 FinalizeWindowHandles();
227 STATS_DumpStatsUSER32();
228 dprintf(("user32 exit done\n"));
229}
230//******************************************************************************
231//******************************************************************************
Note: See TracBrowser for help on using the repository browser.