| 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 | /*-------------------------------------------------------------------*/
|
|---|
| 66 | static void APIENTRY cleanup(ULONG reason);
|
|---|
| 67 |
|
|---|
| 68 | extern "C" {
|
|---|
| 69 | //Win32 resource table (produced by wrc)
|
|---|
| 70 | extern DWORD user32_PEResTab;
|
|---|
| 71 | }
|
|---|
| 72 | DWORD hInstanceUser32 = 0;
|
|---|
| 73 |
|
|---|
| 74 | extern INT __cdecl wsnprintfA(LPSTR,UINT,LPCSTR,...);
|
|---|
| 75 |
|
|---|
| 76 | //******************************************************************************
|
|---|
| 77 | #define FONTSDIRECTORY "Fonts"
|
|---|
| 78 | #define REGPATH "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
|
|---|
| 79 | //******************************************************************************
|
|---|
| 80 | static 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 |
|
|---|
| 131 | static 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 | /****************************************************************************/
|
|---|
| 158 | ULONG 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 | if (!InitializeKernel32())
|
|---|
| 177 | return 0;
|
|---|
| 178 |
|
|---|
| 179 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
|---|
| 180 |
|
|---|
| 181 | hInstanceUser32 = RegisterLxDll(hModule, DllMain, (PVOID)&user32_PEResTab,
|
|---|
| 182 | USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
|
|---|
| 183 | IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
|---|
| 184 | if(hInstanceUser32 == 0)
|
|---|
| 185 | return 0UL;
|
|---|
| 186 |
|
|---|
| 187 | dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
|
|---|
| 188 |
|
|---|
| 189 | //SvL: Try to start communication with our message spy queue server
|
|---|
| 190 | InitSpyQueue();
|
|---|
| 191 |
|
|---|
| 192 | //SvL: Init win32 PM classes
|
|---|
| 193 | //PH: initializes HAB!
|
|---|
| 194 | if (FALSE == InitPM())
|
|---|
| 195 | return 0UL;
|
|---|
| 196 |
|
|---|
| 197 | InitializeWindowHandles();
|
|---|
| 198 |
|
|---|
| 199 | //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
|
|---|
| 200 | //CB: register internal classes
|
|---|
| 201 | RegisterSystemClasses(hModule);
|
|---|
| 202 |
|
|---|
| 203 | //CB: initialize PM monitor driver
|
|---|
| 204 | MONITOR_Initialize(&MONITOR_PrimaryMonitor);
|
|---|
| 205 |
|
|---|
| 206 | //PF: migrate windows fonts
|
|---|
| 207 | MigrateWindowsFonts();
|
|---|
| 208 |
|
|---|
| 209 | InitClipboardFormats();
|
|---|
| 210 |
|
|---|
| 211 | RasEntry (RAS_EVENT_User32InitComplete, &hInstanceUser32, sizeof (hInstanceUser32));
|
|---|
| 212 |
|
|---|
| 213 | break;
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 | case 1 :
|
|---|
| 217 | if(hInstanceUser32) {
|
|---|
| 218 | UnregisterLxDll(hInstanceUser32);
|
|---|
| 219 | }
|
|---|
| 220 | STATS_UninitializeUSER32 ();
|
|---|
| 221 | break;
|
|---|
| 222 | default :
|
|---|
| 223 | return 0UL;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | /***********************************************************/
|
|---|
| 227 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 228 | /***********************************************************/
|
|---|
| 229 | return 1UL;
|
|---|
| 230 | }
|
|---|
| 231 | //******************************************************************************
|
|---|
| 232 | //******************************************************************************
|
|---|
| 233 | void APIENTRY cleanupUser32(ULONG ulReason)
|
|---|
| 234 | {
|
|---|
| 235 | dprintf(("user32 exit\n"));
|
|---|
| 236 |
|
|---|
| 237 | //SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
|
|---|
| 238 | //// RestoreCursor();
|
|---|
| 239 |
|
|---|
| 240 | //Destroy CD notification window
|
|---|
| 241 | WinDestroyWindow(hwndCD);
|
|---|
| 242 | DestroyDesktopWindow();
|
|---|
| 243 | Win32BaseWindow::DestroyAll();
|
|---|
| 244 | UnregisterSystemClasses();
|
|---|
| 245 | Win32WndClass::DestroyAll();
|
|---|
| 246 | MONITOR_Finalize(&MONITOR_PrimaryMonitor);
|
|---|
| 247 | SYSCOLOR_Save();
|
|---|
| 248 | CloseSpyQueue();
|
|---|
| 249 | FinalizeWindowHandles();
|
|---|
| 250 | STATS_DumpStatsUSER32();
|
|---|
| 251 | dprintf(("user32 exit done\n"));
|
|---|
| 252 | }
|
|---|
| 253 | //******************************************************************************
|
|---|
| 254 | //******************************************************************************
|
|---|