| 1 | /* $Id: initterm.cpp,v 1.34 2003-01-21 11:22:08 sandervl Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * USER32 DLL entry point
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1998 Sander van Leeuwen
|
|---|
| 6 | * Copyright 1998 Peter Fitzsimmons
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #define INCL_DOSMODULEMGR
|
|---|
| 12 | #define INCL_DOSPROCESS
|
|---|
| 13 | #define INCL_DOSSEMAPHORES
|
|---|
| 14 | #define INCL_DOSMISC
|
|---|
| 15 | #define INCL_DOSERRORS
|
|---|
| 16 | #define INCL_WINSHELLDATA
|
|---|
| 17 | #define INCL_WINERRORS
|
|---|
| 18 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 19 | #include <stdlib.h>
|
|---|
| 20 | #include <stdio.h>
|
|---|
| 21 | #include <string.h>
|
|---|
| 22 | #include <odin.h>
|
|---|
| 23 | #include <misc.h> /*PLF Wed 98-03-18 23:18:29*/
|
|---|
| 24 | #include <win32type.h>
|
|---|
| 25 | #include <win32api.h>
|
|---|
| 26 | #include <winconst.h>
|
|---|
| 27 | #include <odinlx.h>
|
|---|
| 28 | #include <spy.h>
|
|---|
| 29 | #include <monitor.h>
|
|---|
| 30 | #include <exitlist.h>
|
|---|
| 31 | #include <initdll.h>
|
|---|
| 32 | #include <stats.h>
|
|---|
| 33 |
|
|---|
| 34 | #include "pmwindow.h"
|
|---|
| 35 | #include "win32wdesktop.h"
|
|---|
| 36 | #include "win32wndhandle.h"
|
|---|
| 37 | #include "syscolor.h"
|
|---|
| 38 | #include "initterm.h"
|
|---|
| 39 | #include "auxthread.h"
|
|---|
| 40 |
|
|---|
| 41 | #define DBG_LOCALLOG DBG_initterm
|
|---|
| 42 | #include "dbglocal.h"
|
|---|
| 43 |
|
|---|
| 44 | extern INT __cdecl wsnprintfA(LPSTR,UINT,LPCSTR,...);
|
|---|
| 45 |
|
|---|
| 46 | // Win32 resource table (produced by wrc)
|
|---|
| 47 | extern DWORD user32_PEResTab;
|
|---|
| 48 |
|
|---|
| 49 | DWORD hInstanceUser32 = 0;
|
|---|
| 50 |
|
|---|
| 51 | BOOL fVersionWarp3 = FALSE;
|
|---|
| 52 |
|
|---|
| 53 | #define FONTSDIRECTORY "Fonts"
|
|---|
| 54 | #define REGPATH "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
|
|---|
| 55 |
|
|---|
| 56 | static void MigrateWindowsFonts()
|
|---|
| 57 | {
|
|---|
| 58 | HKEY hkFonts,hkOS2Fonts;
|
|---|
| 59 | char buffer[512];
|
|---|
| 60 | UINT len;
|
|---|
| 61 |
|
|---|
| 62 | if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGPATH ,0, KEY_ALL_ACCESS, &hkFonts) == 0)
|
|---|
| 63 | {
|
|---|
| 64 | DWORD dwIndex, dwType;
|
|---|
| 65 | char subKeyName[255], dataArray[512];
|
|---|
| 66 | DWORD sizeOfSubKeyName = 254, sizeOfDataArray = 511;
|
|---|
| 67 |
|
|---|
| 68 | // loop over all values of the current key
|
|---|
| 69 | for (dwIndex=0;
|
|---|
| 70 | RegEnumValueA(hkFonts, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, &dwType ,(LPBYTE)dataArray, &sizeOfDataArray) != ERROR_NO_MORE_ITEMS_W;
|
|---|
| 71 | ++dwIndex, sizeOfSubKeyName = 254, sizeOfDataArray = 511)
|
|---|
| 72 | {
|
|---|
| 73 | HDIR hdirFindHandle = HDIR_CREATE;
|
|---|
| 74 | FILEFINDBUF3 FindBuffer = {0};
|
|---|
| 75 | ULONG ulResultBufLen = sizeof(FILEFINDBUF3);
|
|---|
| 76 | ULONG ulFindCount = 1, ret;
|
|---|
| 77 | APIRET rc = NO_ERROR;
|
|---|
| 78 |
|
|---|
| 79 | GetWindowsDirectoryA( buffer, sizeof(buffer) );
|
|---|
| 80 | wsnprintfA( buffer, sizeof(buffer), "%s\\%s\\%s", buffer, FONTSDIRECTORY, dataArray );
|
|---|
| 81 |
|
|---|
| 82 | rc = DosFindFirst( buffer, &hdirFindHandle, FILE_NORMAL,&FindBuffer, ulResultBufLen, &ulFindCount, FIL_STANDARD);
|
|---|
| 83 | //Check that file actaully exist
|
|---|
| 84 | if ( rc == NO_ERROR && !(FindBuffer.attrFile & FILE_DIRECTORY))
|
|---|
| 85 | {
|
|---|
| 86 | //Check OS/2 INI profile for font entry
|
|---|
| 87 | len = PrfQueryProfileString(HINI_PROFILE, "PM_Fonts", dataArray,
|
|---|
| 88 | NULL, (PVOID)subKeyName, (LONG)sizeof(subKeyName));
|
|---|
| 89 |
|
|---|
| 90 | //If it doesn't exist OR if it's outdated
|
|---|
| 91 | if(len == 0 || strcmp(subKeyName, buffer))
|
|---|
| 92 | {
|
|---|
| 93 | dprintf(("Migrating font %s to OS/2",dataArray));
|
|---|
| 94 |
|
|---|
| 95 | ret = GpiLoadFonts(0, buffer);
|
|---|
| 96 | if(ret == FALSE) {
|
|---|
| 97 | dprintf(("GpiLoadFonts %s failed with %x", buffer, WinGetLastError(0)));
|
|---|
| 98 | }
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | DosFindClose(hdirFindHandle);
|
|---|
| 102 | }
|
|---|
| 103 | RegCloseKey(hkFonts);
|
|---|
| 104 | }
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | static BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
|---|
| 108 | {
|
|---|
| 109 | switch (fdwReason)
|
|---|
| 110 | {
|
|---|
| 111 | case DLL_PROCESS_ATTACH:
|
|---|
| 112 | case DLL_THREAD_ATTACH:
|
|---|
| 113 | case DLL_THREAD_DETACH:
|
|---|
| 114 | return TRUE;
|
|---|
| 115 | case DLL_PROCESS_DETACH:
|
|---|
| 116 | {
|
|---|
| 117 | StopAuxThread();
|
|---|
| 118 | return TRUE;
|
|---|
| 119 | }
|
|---|
| 120 | default:
|
|---|
| 121 | break;
|
|---|
| 122 | }
|
|---|
| 123 | return FALSE;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | ULONG SYSTEM DLL_InitUser32(ULONG hModule)
|
|---|
| 127 | {
|
|---|
| 128 | APIRET rc;
|
|---|
| 129 |
|
|---|
| 130 | ULONG version[2];
|
|---|
| 131 | rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
|
|---|
| 132 | if (rc == 0)
|
|---|
| 133 | {
|
|---|
| 134 | if (version[0] >= 20 && version[1] <= 30)
|
|---|
| 135 | fVersionWarp3 = TRUE;
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | STATS_InitializeUSER32();
|
|---|
| 139 |
|
|---|
| 140 | ParseLogStatusUSER32();
|
|---|
| 141 |
|
|---|
| 142 | if (!InitializeKernel32())
|
|---|
| 143 | return 0;
|
|---|
| 144 |
|
|---|
| 145 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
|---|
| 146 |
|
|---|
| 147 | hInstanceUser32 = RegisterLxDll(hModule, DllMain, (PVOID)&user32_PEResTab,
|
|---|
| 148 | USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
|
|---|
| 149 | IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
|---|
| 150 | if(hInstanceUser32 == 0)
|
|---|
| 151 | return 0UL;
|
|---|
| 152 |
|
|---|
| 153 | dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
|
|---|
| 154 |
|
|---|
| 155 | //SvL: Try to start communication with our message spy queue server
|
|---|
| 156 | InitSpyQueue();
|
|---|
| 157 |
|
|---|
| 158 | //SvL: Init win32 PM classes
|
|---|
| 159 | //PH: initializes HAB!
|
|---|
| 160 | if (FALSE == InitPM())
|
|---|
| 161 | return 0UL;
|
|---|
| 162 |
|
|---|
| 163 | InitializeWindowHandles();
|
|---|
| 164 |
|
|---|
| 165 | //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
|
|---|
| 166 | //CB: register internal classes
|
|---|
| 167 | RegisterSystemClasses(hModule);
|
|---|
| 168 |
|
|---|
| 169 | //CB: initialize PM monitor driver
|
|---|
| 170 | MONITOR_Initialize(&MONITOR_PrimaryMonitor);
|
|---|
| 171 |
|
|---|
| 172 | //PF: migrate windows fonts
|
|---|
| 173 | MigrateWindowsFonts();
|
|---|
| 174 |
|
|---|
| 175 | InitClipboardFormats();
|
|---|
| 176 |
|
|---|
| 177 | RasEntry (RAS_EVENT_User32InitComplete, &hInstanceUser32, sizeof (hInstanceUser32));
|
|---|
| 178 |
|
|---|
| 179 | return EXITLIST_USER32;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | void SYSTEM DLL_TermUser32(ULONG hModule)
|
|---|
| 183 | {
|
|---|
| 184 | dprintf(("user32 exit\n"));
|
|---|
| 185 |
|
|---|
| 186 | //SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
|
|---|
| 187 | //// RestoreCursor();
|
|---|
| 188 |
|
|---|
| 189 | //Destroy CD notification window
|
|---|
| 190 | WinDestroyWindow(hwndCD);
|
|---|
| 191 | DestroyDesktopWindow();
|
|---|
| 192 | Win32BaseWindow::DestroyAll();
|
|---|
| 193 | UnregisterSystemClasses();
|
|---|
| 194 | Win32WndClass::DestroyAll();
|
|---|
| 195 | MONITOR_Finalize(&MONITOR_PrimaryMonitor);
|
|---|
| 196 | SYSCOLOR_Save();
|
|---|
| 197 | CloseSpyQueue();
|
|---|
| 198 | FinalizeWindowHandles();
|
|---|
| 199 | STATS_DumpStatsUSER32();
|
|---|
| 200 | dprintf(("user32 exit done\n"));
|
|---|
| 201 |
|
|---|
| 202 | if (hInstanceUser32) {
|
|---|
| 203 | UnregisterLxDll(hInstanceUser32);
|
|---|
| 204 | }
|
|---|
| 205 | STATS_UninitializeUSER32();
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | ULONG SYSTEM DLL_Init(ULONG hModule)
|
|---|
| 209 | {
|
|---|
| 210 | if (DLL_InitDefault(hModule) == -1)
|
|---|
| 211 | return -1;
|
|---|
| 212 | return DLL_InitUser32(hModule);
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | void SYSTEM DLL_Term(ULONG hModule)
|
|---|
| 216 | {
|
|---|
| 217 | DLL_TermUser32(hModule);
|
|---|
| 218 | DLL_TermDefault(hModule);
|
|---|
| 219 | }
|
|---|