00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #define INCL_DOSMODULEMGR
00027 #define INCL_DOSPROCESS
00028 #define INCL_DOSSEMAPHORES
00029 #define INCL_DOSMISC
00030 #define INCL_DOSERRORS
00031 #include <os2wrap.h>
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035 #include <odin.h>
00036 #include <misc.h>
00037 #include <win32type.h>
00038 #include <win32api.h>
00039 #include <winconst.h>
00040 #include <odinlx.h>
00041 #include <spy.h>
00042 #include <monitor.h>
00043 #include "pmwindow.h"
00044 #include "win32wdesktop.h"
00045 #include "syscolor.h"
00046 #include "initterm.h"
00047 #include <exitlist.h>
00048 #include <initdll.h>
00049 #include <stats.h>
00050
00051 #define DBG_LOCALLOG DBG_initterm
00052 #include "dbglocal.h"
00053
00054
00055
00056
00057
00058
00059
00060 static void APIENTRY cleanup(ULONG reason);
00061
00062 extern "C" {
00063
00064 extern DWORD user32_PEResTab;
00065 }
00066 DWORD hInstanceUser32 = 0;
00067
00068
00069
00070
00071
00072
00073
00074 static char PMKBDHK_MODULE[16] = "PMKBDHK";
00075 #define PMKBDHK_HOOK_INIT "hookInit"
00076 #define PMKBDHK_HOOK_TERM "hookKill"
00077
00078 static BOOL pmkbdhk_installed = FALSE;
00079 static HMODULE hmodPMKBDHK;
00080
00081 static PVOID (*APIENTRY pfnHookInit)(HAB);
00082 static BOOL (*APIENTRY pfnHookTerm)(void);
00083
00084
00085 extern HAB hab;
00086
00087
00088
00089 void WIN32API SetCustomPMHookDll(LPSTR pszKbdDllName)
00090 {
00091 strcpy(PMKBDHK_MODULE, pszKbdDllName);
00092 }
00093
00094
00095 void pmkbdhk_initialize(HAB _hab)
00096 {
00097 APIRET rc;
00098
00099 if (pmkbdhk_installed == FALSE)
00100 {
00101 CHAR szBuf[260];
00102
00103
00104 rc = DosLoadModule(szBuf,
00105 sizeof(szBuf),
00106 PMKBDHK_MODULE,
00107 &hmodPMKBDHK);
00108 if (NO_ERROR != rc)
00109 {
00110 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed rc=%d\n",
00111 _hab,
00112 rc));
00113
00114 return;
00115 }
00116
00117
00118 rc = DosQueryProcAddr(hmodPMKBDHK,
00119 0,
00120 PMKBDHK_HOOK_INIT,
00121 (PFN*)&pfnHookInit);
00122 if (NO_ERROR == rc)
00123 rc = DosQueryProcAddr(hmodPMKBDHK,
00124 0,
00125 PMKBDHK_HOOK_TERM,
00126 (PFN*)&pfnHookTerm);
00127
00128 if (NO_ERROR != rc)
00129 {
00130 dprintf(("USER32: pmkbdhk_initalize(%08xh) failed importing functions, rc=%d\n",
00131 _hab,
00132 rc));
00133
00134
00135 DosFreeModule(hmodPMKBDHK);
00136 hmodPMKBDHK = NULLHANDLE;
00137
00138 return;
00139 }
00140
00141
00142 pfnHookInit(_hab);
00143
00144
00145 pmkbdhk_installed = TRUE;
00146 }
00147 }
00148
00149
00150 void pmkbdhk_terminate(void)
00151 {
00152 if (pmkbdhk_installed == TRUE)
00153 {
00154
00155 pfnHookTerm();
00156
00157
00158 pmkbdhk_installed = TRUE;
00159 }
00160
00161
00162 if (NULLHANDLE != hmodPMKBDHK)
00163 {
00164 APIRET rc = DosFreeModule(hmodPMKBDHK);
00165 if (NO_ERROR != rc)
00166 {
00167 dprintf(("USER32: pmkbdhk_terminate() failed rc=%d\n",
00168 rc));
00169
00170 hmodPMKBDHK = NULLHANDLE;
00171 }
00172 }
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182 ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag)
00183 {
00184 size_t i;
00185 APIRET rc;
00186 ULONG version[2];
00187
00188
00189
00190
00191
00192
00193
00194 switch (ulFlag) {
00195 case 0 :
00196 ParseLogStatusUSER32();
00197
00198 InitializeKernel32();
00199 CheckVersionFromHMOD(PE2LX_VERSION, hModule);
00200
00201 hInstanceUser32 = RegisterLxDll(hModule, 0, (PVOID)&user32_PEResTab,
00202 USER32_MAJORIMAGE_VERSION, USER32_MINORIMAGE_VERSION,
00203 IMAGE_SUBSYSTEM_WINDOWS_GUI);
00204 if(hInstanceUser32 == 0)
00205 return 0UL;
00206
00207 dprintf(("user32 init %s %s (%x)", __DATE__, __TIME__, inittermUser32));
00208
00209
00210 InitSpyQueue();
00211
00212
00213
00214 if (FALSE == InitPM())
00215 return 0UL;
00216
00217
00218 pmkbdhk_initialize(hab);
00219
00220
00221
00222 RegisterSystemClasses(hModule);
00223
00224
00225 MONITOR_Initialize(&MONITOR_PrimaryMonitor);
00226
00227 break;
00228
00229
00230 case 1 :
00231 if(hInstanceUser32) {
00232 UnregisterLxDll(hInstanceUser32);
00233 }
00234 break;
00235 default :
00236 return 0UL;
00237 }
00238
00239
00240
00241
00242 return 1UL;
00243 }
00244
00245
00246 void APIENTRY cleanupUser32(ULONG ulReason)
00247 {
00248 dprintf(("user32 exit\n"));
00249
00250
00251 pmkbdhk_terminate();
00252
00253
00254
00255
00256
00257 WinDestroyWindow(hwndCD);
00258 DestroyDesktopWindow();
00259 Win32BaseWindow::DestroyAll();
00260 UnregisterSystemClasses();
00261 Win32WndClass::DestroyAll();
00262 MONITOR_Finalize(&MONITOR_PrimaryMonitor);
00263 SYSCOLOR_Save();
00264 CloseSpyQueue();
00265 STATS_DumpStatsUSER32();
00266 dprintf(("user32 exit done\n"));
00267 }
00268
00269