| 1 | /*
|
|---|
| 2 | * DLL entry point
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 1998 Sander van Leeuwen
|
|---|
| 5 | * Copyright 1998 Peter Fitzsimmons
|
|---|
| 6 | *
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | //
|
|---|
| 12 | // @todo Custom Build is broken ATM:
|
|---|
| 13 | //
|
|---|
| 14 | // 1. inittermXXX()/cleanupXXX() are now DLL_InitXXX/DLL_TermXXX
|
|---|
| 15 | // (see the respective initterm.cpp files for more info).
|
|---|
| 16 | // 2. There is no inittermXXX.cpp files any longer (all initialization functions
|
|---|
| 17 | // are in XXX/initterm.cpp) so a define (e.g. CUSTOMBUILD) is necessary to
|
|---|
| 18 | // disable compilation multiple versions of DLL_Init()/DLL_Term().
|
|---|
| 19 | // N. ...
|
|---|
| 20 | //
|
|---|
| 21 |
|
|---|
| 22 | #define INCL_DOSMODULEMGR
|
|---|
| 23 | #define INCL_DOSMISC
|
|---|
| 24 | #define INCL_DOSPROCESS
|
|---|
| 25 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 26 | #include <stdlib.h>
|
|---|
| 27 | #include <stdio.h>
|
|---|
| 28 | #include <string.h>
|
|---|
| 29 | #include <odin.h>
|
|---|
| 30 | #include <win32api.h>
|
|---|
| 31 | #include <win32type.h>
|
|---|
| 32 | #include <odinapi.h>
|
|---|
| 33 | #include <winconst.h>
|
|---|
| 34 | #include <odinlx.h>
|
|---|
| 35 | #include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
|
|---|
| 36 | #include <initdll.h>
|
|---|
| 37 | #include <exitlist.h>
|
|---|
| 38 | #include "ordinals.h"
|
|---|
| 39 |
|
|---|
| 40 | BOOL fVersionWarp3 = FALSE;
|
|---|
| 41 | static HKEY hKeyClassesRoot = 0;
|
|---|
| 42 | static HKEY hKeyCurrentUser = 0;
|
|---|
| 43 | static HKEY hKeyLocalMachine = 0;
|
|---|
| 44 | static HKEY hKeyUsers = 0;
|
|---|
| 45 |
|
|---|
| 46 | static HMODULE hDllAdvapi32 = 0;
|
|---|
| 47 | static HMODULE hDllGdi32 = 0;
|
|---|
| 48 |
|
|---|
| 49 | #ifdef __IBMCPP__
|
|---|
| 50 | extern "C" {
|
|---|
| 51 |
|
|---|
| 52 | ULONG APIENTRY inittermKernel32(ULONG hModule);
|
|---|
| 53 | void APIENTRY cleanupKernel32(ULONG hModule);
|
|---|
| 54 |
|
|---|
| 55 | ULONG APIENTRY inittermUser32(ULONG hModule, ULONG ulFlag);
|
|---|
| 56 | void APIENTRY cleanupUser32(ULONG ulReason);
|
|---|
| 57 | ULONG APIENTRY inittermOdinCtrl(ULONG hModule, ULONG ulFlag);
|
|---|
| 58 |
|
|---|
| 59 | ULONG APIENTRY inittermWinmm(ULONG hModule, ULONG ulFlag);
|
|---|
| 60 | ULONG APIENTRY inittermShell32(ULONG hModule, ULONG ulFlag);
|
|---|
| 61 | ULONG APIENTRY inittermOle32(ULONG hModule, ULONG ulFlag);
|
|---|
| 62 | ULONG APIENTRY inittermComdlg32(ULONG hModule, ULONG ulFlag);
|
|---|
| 63 | ULONG APIENTRY inittermComctl32(ULONG hModule, ULONG ulFlag);
|
|---|
| 64 | ULONG APIENTRY inittermGdi32(ULONG hModule, ULONG ulFlag);
|
|---|
| 65 | ULONG APIENTRY inittermNTDLL(ULONG hModule, ULONG ulFlag);
|
|---|
| 66 | ULONG APIENTRY inittermWsock32(ULONG hModule, ULONG ulFlag);
|
|---|
| 67 | ULONG APIENTRY inittermWininet(ULONG hModule, ULONG ulFlag);
|
|---|
| 68 | ULONG APIENTRY inittermRpcrt4(ULONG hModule, ULONG ulFlag);
|
|---|
| 69 | ULONG APIENTRY inittermAvifil32(ULONG hModule, ULONG ulFlag);
|
|---|
| 70 | ULONG APIENTRY inittermQuartz(ULONG hModule, ULONG ulFlag);
|
|---|
| 71 | ULONG APIENTRY inittermRiched32(ULONG hModule, ULONG ulFlag);
|
|---|
| 72 | ULONG APIENTRY inittermWnaspi32(ULONG hModule, ULONG ulFlag);
|
|---|
| 73 | ULONG APIENTRY inittermUxTheme(ULONG hModule, ULONG ulFlag);
|
|---|
| 74 | ULONG APIENTRY inittermDInput(ULONG hModule, ULONG ulFlag);
|
|---|
| 75 | ULONG APIENTRY inittermDSound(ULONG hModule, ULONG ulFlag);
|
|---|
| 76 | ULONG APIENTRY inittermWinSpool(ULONG hModule, ULONG ulFlag);
|
|---|
| 77 | ULONG APIENTRY inittermDDraw(ULONG hModule, ULONG ulFlag);
|
|---|
| 78 | ULONG APIENTRY inittermNTDLL(ULONG hModule, ULONG ulFlag);
|
|---|
| 79 | ULONG APIENTRY inittermMSVCRT(ULONG hModule, ULONG ulFlag);
|
|---|
| 80 | ULONG APIENTRY inittermImm32(ULONG hModule, ULONG ulFlag);
|
|---|
| 81 | ULONG APIENTRY inittermCrypt32(ULONG hModule, ULONG ulFlag);
|
|---|
| 82 | ULONG APIENTRY inittermOleacc(ULONG hModule, ULONG ulFlag);
|
|---|
| 83 | ULONG APIENTRY inittermmscms(ULONG hModule, ULONG ulFlag);
|
|---|
| 84 | ULONG APIENTRY inittermRsaenh(ULONG hModule, ULONG ulFlag);
|
|---|
| 85 | ULONG APIENTRY inittermSecur32(ULONG hModule, ULONG ulFlag);
|
|---|
| 86 |
|
|---|
| 87 | /*-------------------------------------------------------------------*/
|
|---|
| 88 | /* A clean up routine registered with DosExitList must be used if */
|
|---|
| 89 | /* runtime calls are required and the runtime is dynamically linked. */
|
|---|
| 90 | /* This will guarantee that this clean up routine is run before the */
|
|---|
| 91 | /* library DLL is terminated. */
|
|---|
| 92 | /*-------------------------------------------------------------------*/
|
|---|
| 93 | static void APIENTRY cleanup(ULONG reason);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /****************************************************************************/
|
|---|
| 97 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
|---|
| 98 | /* loader when it loads and frees this DLL for each process that accesses */
|
|---|
| 99 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
|---|
| 100 | /* and the last time it is freed for a particular process. The system */
|
|---|
| 101 | /* linkage convention MUST be used because the operating system loader is */
|
|---|
| 102 | /* calling this function. */
|
|---|
| 103 | /****************************************************************************/
|
|---|
| 104 | ULONG SYSTEM _DLL_InitTerm(ULONG hModule, ULONG ulFlag)
|
|---|
| 105 | {
|
|---|
| 106 | size_t i;
|
|---|
| 107 | APIRET rc;
|
|---|
| 108 | ULONG version[2];
|
|---|
| 109 | static BOOL fInit = FALSE, fExit = FALSE;
|
|---|
| 110 |
|
|---|
| 111 | /*-------------------------------------------------------------------------*/
|
|---|
| 112 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
|---|
| 113 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
|---|
| 114 | /* termination should be performed. */
|
|---|
| 115 | /*-------------------------------------------------------------------------*/
|
|---|
| 116 |
|
|---|
| 117 | switch (ulFlag) {
|
|---|
| 118 | case 0 :
|
|---|
| 119 | {
|
|---|
| 120 | /*******************************************************************/
|
|---|
| 121 | /* The C run-time environment initialization function must be */
|
|---|
| 122 | /* called before any calls to C run-time functions that are not */
|
|---|
| 123 | /* inlined. */
|
|---|
| 124 | /*******************************************************************/
|
|---|
| 125 |
|
|---|
| 126 | if (_CRT_init() == -1)
|
|---|
| 127 | return 0UL;
|
|---|
| 128 | ctordtorInit();
|
|---|
| 129 |
|
|---|
| 130 | rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
|
|---|
| 131 | if(rc == 0){
|
|---|
| 132 | if(version[0] >= 20 && version[1] <= 30) {
|
|---|
| 133 | fVersionWarp3 = TRUE;
|
|---|
| 134 | }
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | /*******************************************************************/
|
|---|
| 138 | /* A DosExitList routine must be used to clean up if runtime calls */
|
|---|
| 139 | /* are required and the runtime is dynamically linked. */
|
|---|
| 140 | /*******************************************************************/
|
|---|
| 141 | rc = DosExitList(EXITLIST_KERNEL32|EXLST_ADD, cleanup);
|
|---|
| 142 | if(rc)
|
|---|
| 143 | return 0UL;
|
|---|
| 144 |
|
|---|
| 145 | char szErrName[CCHMAXPATH];
|
|---|
| 146 | rc = DosLoadModule(szErrName, sizeof(szErrName), "XXODIN32", &hModule);
|
|---|
| 147 | if(rc != 0) {
|
|---|
| 148 | return 0;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_ClassesRoot",&hKeyClassesRoot)!=ERROR_SUCCESS_W) {
|
|---|
| 152 | return 0;
|
|---|
| 153 | }
|
|---|
| 154 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_CurrentUser",&hKeyCurrentUser)!=ERROR_SUCCESS_W) {
|
|---|
| 155 | return 0;
|
|---|
| 156 | }
|
|---|
| 157 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_LocalMachine",&hKeyLocalMachine)!=ERROR_SUCCESS_W) {
|
|---|
| 158 | return 0;
|
|---|
| 159 | }
|
|---|
| 160 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_Users",&hKeyUsers)!=ERROR_SUCCESS_W) {
|
|---|
| 161 | return 0;
|
|---|
| 162 | }
|
|---|
| 163 | SetRegistryRootKey(HKEY_CLASSES_ROOT, hKeyClassesRoot);
|
|---|
| 164 | SetRegistryRootKey(HKEY_CURRENT_USER, hKeyCurrentUser);
|
|---|
| 165 | SetRegistryRootKey(HKEY_LOCAL_MACHINE, hKeyLocalMachine);
|
|---|
| 166 | SetRegistryRootKey(HKEY_USERS, hKeyUsers);
|
|---|
| 167 |
|
|---|
| 168 | SetCustomBuildName("NTDLL.DLL", 0);
|
|---|
| 169 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 170 | return 0UL;
|
|---|
| 171 |
|
|---|
| 172 | SetCustomBuildName("KERNEL32.DLL", ORDINALBASE_KERNEL32);
|
|---|
| 173 | rc = inittermKernel32(hModule, ulFlag);
|
|---|
| 174 | if(rc == 0)
|
|---|
| 175 | return 0UL;
|
|---|
| 176 |
|
|---|
| 177 | SetCustomBuildName("USER32.DLL", ORDINALBASE_USER32);
|
|---|
| 178 | rc = inittermUser32(hModule, ulFlag);
|
|---|
| 179 | if(rc == 0)
|
|---|
| 180 | return 0UL;
|
|---|
| 181 |
|
|---|
| 182 | SetCustomBuildName("GDI32.DLL", ORDINALBASE_GDI32);
|
|---|
| 183 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 184 | return 0UL;
|
|---|
| 185 |
|
|---|
| 186 | SetCustomBuildName("ADVAPI32.DLL", 0);
|
|---|
| 187 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 188 | return 0UL;
|
|---|
| 189 |
|
|---|
| 190 | SetCustomBuildName("VERSION.DLL", 0);
|
|---|
| 191 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 192 | return 0UL;
|
|---|
| 193 |
|
|---|
| 194 | SetCustomBuildName("WSOCK32.DLL", ORDINALBASE_WSOCK32);
|
|---|
| 195 | rc = inittermWsock32(hModule, ulFlag);
|
|---|
| 196 | if(rc == 0)
|
|---|
| 197 | return 0UL;
|
|---|
| 198 |
|
|---|
| 199 | SetCustomBuildName("WINMM.DLL", 0);
|
|---|
| 200 | rc = inittermWinmm(hModule, ulFlag);
|
|---|
| 201 | if(rc == 0)
|
|---|
| 202 | return 0UL;
|
|---|
| 203 |
|
|---|
| 204 | SetCustomBuildName("RPCRT4.DLL", 0);
|
|---|
| 205 | rc = inittermRpcrt4(hModule, ulFlag);
|
|---|
| 206 | if(rc == 0)
|
|---|
| 207 | return 0UL;
|
|---|
| 208 |
|
|---|
| 209 | SetCustomBuildName("OLE32.DLL", ORDINALBASE_OLE32);
|
|---|
| 210 | rc = inittermOle32(hModule, ulFlag);
|
|---|
| 211 | if(rc == 0)
|
|---|
| 212 | return 0UL;
|
|---|
| 213 |
|
|---|
| 214 | SetCustomBuildName("COMCTL32.DLL", ORDINALBASE_COMCTL32);
|
|---|
| 215 | rc = inittermComctl32(hModule, ulFlag);
|
|---|
| 216 | if(rc == 0)
|
|---|
| 217 | return 0UL;
|
|---|
| 218 |
|
|---|
| 219 | SetCustomBuildName("SHLWAPI.DLL", ORDINALBASE_SHLWAPI);
|
|---|
| 220 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 221 | return 0UL;
|
|---|
| 222 |
|
|---|
| 223 | SetCustomBuildName("SHELL32.DLL", ORDINALBASE_SHELL32);
|
|---|
| 224 | rc = inittermShell32(hModule, ulFlag);
|
|---|
| 225 | if(rc == 0)
|
|---|
| 226 | return 0UL;
|
|---|
| 227 |
|
|---|
| 228 | SetCustomBuildName("COMDLG32.DLL", 0);
|
|---|
| 229 | rc = inittermComdlg32(hModule, ulFlag);
|
|---|
| 230 | if(rc == 0)
|
|---|
| 231 | return 0UL;
|
|---|
| 232 |
|
|---|
| 233 | SetCustomBuildName("RICHED32.DLL", 0);
|
|---|
| 234 | rc = inittermRiched32(hModule, ulFlag);
|
|---|
| 235 | if(rc == 0)
|
|---|
| 236 | return 0UL;
|
|---|
| 237 |
|
|---|
| 238 | SetCustomBuildName(NULL, 0);
|
|---|
| 239 | break;
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | case 1 :
|
|---|
| 243 | {
|
|---|
| 244 | inittermComdlg32(hModule, ulFlag);
|
|---|
| 245 | inittermShell32(hModule, ulFlag);
|
|---|
| 246 | inittermComctl32(hModule, ulFlag);
|
|---|
| 247 | inittermOle32(hModule, ulFlag);
|
|---|
| 248 | inittermRpcrt4(hModule, ulFlag);
|
|---|
| 249 | inittermWinmm(hModule, ulFlag);
|
|---|
| 250 | inittermWsock32(hModule, ulFlag);
|
|---|
| 251 | inittermUser32(hModule, ulFlag);
|
|---|
| 252 | inittermKernel32(hModule, ulFlag);
|
|---|
| 253 | break;
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | default :
|
|---|
| 257 | return 0UL;
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | /***********************************************************/
|
|---|
| 261 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 262 | /***********************************************************/
|
|---|
| 263 | return 1UL;
|
|---|
| 264 | }
|
|---|
| 265 | //******************************************************************************
|
|---|
| 266 | //******************************************************************************
|
|---|
| 267 | static void APIENTRY cleanup(ULONG ulReason)
|
|---|
| 268 | {
|
|---|
| 269 | cleanupUser32(ulReason);
|
|---|
| 270 | cleanupKernel32(ulReason);
|
|---|
| 271 | ctordtorTerm();
|
|---|
| 272 | _CRT_term();
|
|---|
| 273 | DosExitList(EXLST_EXIT, cleanup);
|
|---|
| 274 | return ;
|
|---|
| 275 | }
|
|---|
| 276 | //******************************************************************************
|
|---|
| 277 | //******************************************************************************
|
|---|
| 278 | ULONG APIENTRY O32__DLL_InitTerm(ULONG handle, ULONG flag);
|
|---|
| 279 | //******************************************************************************
|
|---|
| 280 | BOOL APIENTRY InitializeKernel32()
|
|---|
| 281 | {
|
|---|
| 282 | HMODULE hModule;
|
|---|
| 283 |
|
|---|
| 284 | DosQueryModuleHandleStrict("WGSS50", &hModule);
|
|---|
| 285 | return O32__DLL_InitTerm(hModule, 0) != 0;
|
|---|
| 286 | }
|
|---|
| 287 | //******************************************************************************
|
|---|
| 288 | //******************************************************************************
|
|---|
| 289 | #else
|
|---|
| 290 | #error message("compiler is not supported");
|
|---|
| 291 | #endif
|
|---|