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