| 1 | /* $Id: inituser32.cpp,v 1.17 2003-11-12 14:10:19 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 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 33 | #include <stdlib.h>
|
|---|
| 34 | #include <stdio.h>
|
|---|
| 35 | #include <string.h>
|
|---|
| 36 | #include <odin.h>
|
|---|
| 37 | #include <misc.h> /*PLF Wed 98-03-18 23:18:29*/
|
|---|
| 38 | #include <win32type.h>
|
|---|
| 39 | #include <win32api.h>
|
|---|
| 40 | #include <winconst.h>
|
|---|
| 41 | #include <odinlx.h>
|
|---|
| 42 | #include <spy.h>
|
|---|
| 43 | #include <monitor.h>
|
|---|
| 44 | #include <kbdhook.h>
|
|---|
| 45 | #include "pmwindow.h"
|
|---|
| 46 | #include "win32wdesktop.h"
|
|---|
| 47 | #include "win32wndhandle.h"
|
|---|
| 48 | #include "syscolor.h"
|
|---|
| 49 | #include "initterm.h"
|
|---|
| 50 | #include <exitlist.h>
|
|---|
| 51 | #include <initdll.h>
|
|---|
| 52 | #include <stats.h>
|
|---|
| 53 |
|
|---|
| 54 | #define DBG_LOCALLOG DBG_initterm
|
|---|
| 55 | #include "dbglocal.h"
|
|---|
| 56 |
|
|---|
| 57 | /*-------------------------------------------------------------------*/
|
|---|
| 58 | /* A clean up routine registered with DosExitList must be used if */
|
|---|
| 59 | /* runtime calls are required and the runtime is dynamically linked. */
|
|---|
| 60 | /* This will guarantee that this clean up routine is run before the */
|
|---|
| 61 | /* library DLL is terminated. */
|
|---|
| 62 | /*-------------------------------------------------------------------*/
|
|---|
| 63 | static void APIENTRY cleanup(ULONG reason);
|
|---|
| 64 |
|
|---|
| 65 | extern "C" {
|
|---|
| 66 | //Win32 resource table (produced by wrc)
|
|---|
| 67 | extern DWORD user32_PEResTab;
|
|---|
| 68 | }
|
|---|
| 69 | DWORD hInstanceUser32 = 0;
|
|---|
| 70 |
|
|---|
| 71 | extern INT __cdecl wsnprintfA(LPSTR,UINT,LPCSTR,...);
|
|---|
| 72 |
|
|---|
| 73 | //******************************************************************************
|
|---|
| 74 | #define FONTSDIRECTORY "Fonts"
|
|---|
| 75 | #define REGPATH "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
|
|---|
| 76 | //******************************************************************************
|
|---|
| 77 | void MigrateWindowsFonts()
|
|---|
| 78 | {
|
|---|
| 79 | HKEY hkFonts,hkOS2Fonts;
|
|---|
| 80 | char buffer[512];
|
|---|
| 81 | UINT len = GetWindowsDirectoryA( NULL, 0 );
|
|---|
| 82 |
|
|---|
| 83 | if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, REGPATH ,0, KEY_ALL_ACCESS, &hkFonts) == 0)
|
|---|
| 84 | {
|
|---|
| 85 | DWORD dwIndex, dwType;
|
|---|
| 86 | char subKeyName[255], dataArray[512];
|
|---|
| 87 | DWORD sizeOfSubKeyName = 254, sizeOfDataArray = 511;
|
|---|
| 88 |
|
|---|
| 89 | // loop over all values of the current key
|
|---|
| 90 | for (dwIndex=0;
|
|---|
| 91 | RegEnumValueA(hkFonts, dwIndex, subKeyName, &sizeOfSubKeyName, NULL, &dwType ,(LPBYTE)dataArray, &sizeOfDataArray) != ERROR_NO_MORE_ITEMS_W;
|
|---|
| 92 | ++dwIndex, sizeOfSubKeyName = 254, sizeOfDataArray = 511)
|
|---|
| 93 | {
|
|---|
| 94 | //Check OS/2 INI profile for font entry
|
|---|
| 95 | if (!PrfQueryProfileString(HINI_PROFILE, "PM_Fonts", dataArray,
|
|---|
| 96 | NULL, (PVOID)subKeyName, (LONG)sizeof(subKeyName)))
|
|---|
| 97 | {
|
|---|
| 98 | HDIR hdirFindHandle = HDIR_CREATE;
|
|---|
| 99 | FILEFINDBUF3 FindBuffer = {0};
|
|---|
| 100 | ULONG ulResultBufLen = sizeof(FILEFINDBUF3);
|
|---|
| 101 | ULONG ulFindCount = 1;
|
|---|
| 102 | APIRET rc = NO_ERROR;
|
|---|
| 103 |
|
|---|
| 104 | dprintf(("Migrating font %s to OS/2",dataArray));
|
|---|
| 105 |
|
|---|
| 106 | GetWindowsDirectoryA( buffer, len + 1 );
|
|---|
| 107 | wsnprintfA( buffer, sizeof(buffer), "%s\\%s\\%s", buffer, FONTSDIRECTORY, dataArray );
|
|---|
| 108 |
|
|---|
| 109 | rc = DosFindFirst( buffer, &hdirFindHandle, FILE_NORMAL,&FindBuffer, ulResultBufLen, &ulFindCount, FIL_STANDARD);
|
|---|
| 110 |
|
|---|
| 111 | //Check that file actaully exist
|
|---|
| 112 | if ( rc == NO_ERROR && !(FindBuffer.attrFile & FILE_DIRECTORY))
|
|---|
| 113 | {
|
|---|
| 114 | PrfWriteProfileString(HINI_PROFILE,"PM_Fonts",dataArray, buffer);
|
|---|
| 115 | DosFindClose(hdirFindHandle);
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 | }
|
|---|
| 119 | RegCloseKey(hkFonts);
|
|---|
| 120 | }
|
|---|
| 121 | }
|
|---|
| 122 | /****************************************************************************/
|
|---|
| 123 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
|---|
| 124 | /* loader when it loads and frees this DLL for each process that accesses */
|
|---|
| 125 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
|---|
| 126 | /* and the last time it is freed for a particular process. The system */
|
|---|
| 127 | /* linkage convention MUST be used because the operating system loader is */
|
|---|
| 128 | /* calling this function. */
|
|---|
| 129 | /****************************************************************************/
|
|---|
| 130 | ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag)
|
|---|
| 131 | {
|
|---|
| 132 | size_t i;
|
|---|
| 133 | APIRET rc;
|
|---|
| 134 | ULONG version[2];
|
|---|
| 135 |
|
|---|
| 136 | /*-------------------------------------------------------------------------*/
|
|---|
| 137 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
|---|
| 138 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
|---|
| 139 | /* termination should be performed. */
|
|---|
| 140 | /*-------------------------------------------------------------------------*/
|
|---|
| 141 |
|
|---|
| 142 | switch (ulFlag) {
|
|---|
| 143 | case 0 :
|
|---|
| 144 | ParseLogStatusUSER32();
|
|---|
| 145 |
|
|---|
| 146 | InitializeKernel32();
|
|---|
| 147 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
|---|
| 148 |
|
|---|
| 149 | hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&user32_PEResTab,
|
|---|
| 150 | USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
|
|---|
| 151 | IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
|---|
| 152 | if(hInstanceUser32 == 0)
|
|---|
| 153 | return 0UL;
|
|---|
| 154 |
|
|---|
| 155 | dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
|
|---|
| 156 |
|
|---|
| 157 | //SvL: Try to start communication with our message spy queue server
|
|---|
| 158 | InitSpyQueue();
|
|---|
| 159 |
|
|---|
| 160 | //SvL: Init win32 PM classes
|
|---|
| 161 | //PH: initializes HAB!
|
|---|
| 162 | if (FALSE == InitPM())
|
|---|
| 163 | return 0UL;
|
|---|
| 164 |
|
|---|
| 165 | InitializeWindowHandles();
|
|---|
| 166 |
|
|---|
| 167 | //SvL: 18-7-'98, Register system window classes (button, listbox etc etc)
|
|---|
| 168 | //CB: register internal classes
|
|---|
| 169 | RegisterSystemClasses(hModule);
|
|---|
| 170 |
|
|---|
| 171 | //CB: initialize PM monitor driver
|
|---|
| 172 | MONITOR_Initialize(&MONITOR_PrimaryMonitor);
|
|---|
| 173 |
|
|---|
| 174 | //PF: migrate windows fonts
|
|---|
| 175 | MigrateWindowsFonts();
|
|---|
| 176 |
|
|---|
| 177 | break;
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 | case 1 :
|
|---|
| 181 | if(hInstanceUser32) {
|
|---|
| 182 | UnregisterLxDll(hInstanceUser32);
|
|---|
| 183 | }
|
|---|
| 184 | break;
|
|---|
| 185 | default :
|
|---|
| 186 | return 0UL;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | /***********************************************************/
|
|---|
| 190 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 191 | /***********************************************************/
|
|---|
| 192 | return 1UL;
|
|---|
| 193 | }
|
|---|
| 194 | //******************************************************************************
|
|---|
| 195 | //******************************************************************************
|
|---|
| 196 | void APIENTRY cleanupUser32(ULONG ulReason)
|
|---|
| 197 | {
|
|---|
| 198 | dprintf(("user32 exit\n"));
|
|---|
| 199 |
|
|---|
| 200 | //SvL: Causes PM hangs on some (a lot?) machines. Reason unknown.
|
|---|
| 201 | //// RestoreCursor();
|
|---|
| 202 |
|
|---|
| 203 | //Destroy CD notification window
|
|---|
| 204 | WinDestroyWindow(hwndCD);
|
|---|
| 205 | DestroyDesktopWindow();
|
|---|
| 206 | Win32BaseWindow::DestroyAll();
|
|---|
| 207 | UnregisterSystemClasses();
|
|---|
| 208 | Win32WndClass::DestroyAll();
|
|---|
| 209 | MONITOR_Finalize(&MONITOR_PrimaryMonitor);
|
|---|
| 210 | SYSCOLOR_Save();
|
|---|
| 211 | CloseSpyQueue();
|
|---|
| 212 | FinalizeWindowHandles();
|
|---|
| 213 | STATS_DumpStatsUSER32();
|
|---|
| 214 | dprintf(("user32 exit done\n"));
|
|---|
| 215 | }
|
|---|
| 216 | //******************************************************************************
|
|---|
| 217 | //******************************************************************************
|
|---|