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

Last change on this file since 21595 was 21595, checked in by dmik, 14 years ago

user32: Added internal helper RunOnAuxThread() API to perform function calls on a dedicated helper thread.

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