[21802] | 1 | /* $Id: initterm.cpp,v 1.34 2003-01-21 11:22:08 sandervl Exp $
|
---|
| 2 | *
|
---|
[6375] | 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
|
---|
[7155] | 15 | #define INCL_DOSERRORS
|
---|
[10277] | 16 | #define INCL_WINSHELLDATA
|
---|
[10319] | 17 | #define INCL_WINERRORS
|
---|
[21808] | 18 | #define INCL_GPILCIDS
|
---|
[6375] | 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>
|
---|
[21802] | 31 | #include <exitlist.h>
|
---|
| 32 | #include <initdll.h>
|
---|
| 33 | #include <stats.h>
|
---|
| 34 |
|
---|
[6375] | 35 | #include "pmwindow.h"
|
---|
| 36 | #include "win32wdesktop.h"
|
---|
[8202] | 37 | #include "win32wndhandle.h"
|
---|
[6375] | 38 | #include "syscolor.h"
|
---|
| 39 | #include "initterm.h"
|
---|
[21595] | 40 | #include "auxthread.h"
|
---|
[6375] | 41 |
|
---|
[6650] | 42 | #define DBG_LOCALLOG DBG_initterm
|
---|
[6375] | 43 | #include "dbglocal.h"
|
---|
| 44 |
|
---|
[21811] | 45 | extern "C" INT __cdecl wsnprintfA(LPSTR,UINT,LPCSTR,...);
|
---|
[6375] | 46 |
|
---|
[21802] | 47 | // Win32 resource table (produced by wrc)
|
---|
| 48 | extern DWORD user32_PEResTab;
|
---|
| 49 |
|
---|
[6375] | 50 | DWORD hInstanceUser32 = 0;
|
---|
| 51 |
|
---|
[21802] | 52 | BOOL fVersionWarp3 = FALSE;
|
---|
[7155] | 53 |
|
---|
[10284] | 54 | #define FONTSDIRECTORY "Fonts"
|
---|
| 55 | #define REGPATH "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
|
---|
[21802] | 56 |
|
---|
[21595] | 57 | static void MigrateWindowsFonts()
|
---|
[10284] | 58 | {
|
---|
| 59 | HKEY hkFonts,hkOS2Fonts;
|
---|
| 60 | char buffer[512];
|
---|
[10319] | 61 | UINT len;
|
---|
[10595] | 62 |
|
---|
[10284] | 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 | {
|
---|
[10319] | 74 | HDIR hdirFindHandle = HDIR_CREATE;
|
---|
[10595] | 75 | FILEFINDBUF3 FindBuffer = {0};
|
---|
[10319] | 76 | ULONG ulResultBufLen = sizeof(FILEFINDBUF3);
|
---|
[10595] | 77 | ULONG ulFindCount = 1, ret;
|
---|
| 78 | APIRET rc = NO_ERROR;
|
---|
[10284] | 79 |
|
---|
[10319] | 80 | GetWindowsDirectoryA( buffer, sizeof(buffer) );
|
---|
| 81 | wsnprintfA( buffer, sizeof(buffer), "%s\\%s\\%s", buffer, FONTSDIRECTORY, dataArray );
|
---|
[10284] | 82 |
|
---|
[10319] | 83 | rc = DosFindFirst( buffer, &hdirFindHandle, FILE_NORMAL,&FindBuffer, ulResultBufLen, &ulFindCount, FIL_STANDARD);
|
---|
[10595] | 84 | //Check that file actaully exist
|
---|
[10319] | 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));
|
---|
[10284] | 90 |
|
---|
[10319] | 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));
|
---|
[10284] | 95 |
|
---|
[10319] | 96 | ret = GpiLoadFonts(0, buffer);
|
---|
| 97 | if(ret == FALSE) {
|
---|
| 98 | dprintf(("GpiLoadFonts %s failed with %x", buffer, WinGetLastError(0)));
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
[10595] | 101 | }
|
---|
[10319] | 102 | DosFindClose(hdirFindHandle);
|
---|
[10284] | 103 | }
|
---|
| 104 | RegCloseKey(hkFonts);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
[21595] | 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 |
|
---|
[21802] | 127 | ULONG SYSTEM DLL_InitUser32(ULONG hModule)
|
---|
[6375] | 128 | {
|
---|
[21802] | 129 | APIRET rc;
|
---|
[6375] | 130 |
|
---|
[21802] | 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 | }
|
---|
[6375] | 138 |
|
---|
[21802] | 139 | STATS_InitializeUSER32();
|
---|
[21595] | 140 |
|
---|
[21802] | 141 | ParseLogStatusUSER32();
|
---|
[6375] | 142 |
|
---|
[21802] | 143 | if (!InitializeKernel32())
|
---|
[21976] | 144 | return -1;
|
---|
[21649] | 145 |
|
---|
[21802] | 146 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
---|
[6397] | 147 |
|
---|
[21802] | 148 | hInstanceUser32 = RegisterLxDll(hModule, DllMain, (PVOID)&user32_PEResTab,
|
---|
| 149 | USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
|
---|
| 150 | IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
---|
[21976] | 151 | if (hInstanceUser32 == 0)
|
---|
| 152 | return -1;
|
---|
[6375] | 153 |
|
---|
[21824] | 154 | dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, DLL_InitUser32));
|
---|
[6375] | 155 |
|
---|
[21802] | 156 | //SvL: Try to start communication with our message spy queue server
|
---|
| 157 | InitSpyQueue();
|
---|
[6375] | 158 |
|
---|
[21802] | 159 | //SvL: Init win32 PM classes
|
---|
| 160 | //PH: initializes HAB!
|
---|
| 161 | if (FALSE == InitPM())
|
---|
[21976] | 162 | return -1;
|
---|
[10245] | 163 |
|
---|
[21802] | 164 | InitializeWindowHandles();
|
---|
[8202] | 165 |
|
---|
[21802] | 166 | //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
|
---|
| 167 | //CB: register internal classes
|
---|
| 168 | RegisterSystemClasses(hModule);
|
---|
[6375] | 169 |
|
---|
[21802] | 170 | //CB: initialize PM monitor driver
|
---|
| 171 | MONITOR_Initialize(&MONITOR_PrimaryMonitor);
|
---|
[6375] | 172 |
|
---|
[21802] | 173 | //PF: migrate windows fonts
|
---|
| 174 | MigrateWindowsFonts();
|
---|
[10277] | 175 |
|
---|
[21802] | 176 | InitClipboardFormats();
|
---|
[21303] | 177 |
|
---|
[21802] | 178 | RasEntry (RAS_EVENT_User32InitComplete, &hInstanceUser32, sizeof (hInstanceUser32));
|
---|
[21303] | 179 |
|
---|
[21802] | 180 | return EXITLIST_USER32;
|
---|
| 181 | }
|
---|
[10245] | 182 |
|
---|
[21802] | 183 | void SYSTEM DLL_TermUser32(ULONG hModule)
|
---|
| 184 | {
|
---|
| 185 | dprintf(("user32 exit\n"));
|
---|
[10245] | 186 |
|
---|
[21802] | 187 | //SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
|
---|
| 188 | //// RestoreCursor();
|
---|
[6375] | 189 |
|
---|
[21802] | 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();
|
---|
[6375] | 207 | }
|
---|
[21802] | 208 |
|
---|
| 209 | ULONG SYSTEM DLL_Init(ULONG hModule)
|
---|
[6375] | 210 | {
|
---|
[21802] | 211 | if (DLL_InitDefault(hModule) == -1)
|
---|
| 212 | return -1;
|
---|
| 213 | return DLL_InitUser32(hModule);
|
---|
| 214 | }
|
---|
[10245] | 215 |
|
---|
[21802] | 216 | void SYSTEM DLL_Term(ULONG hModule)
|
---|
| 217 | {
|
---|
| 218 | DLL_TermUser32(hModule);
|
---|
| 219 | DLL_TermDefault(hModule);
|
---|
[6375] | 220 | }
|
---|