[6374] | 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 |
|
---|
[21916] | 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 | //
|
---|
[6374] | 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>
|
---|
[6401] | 30 | #include <win32api.h>
|
---|
[6374] | 31 | #include <win32type.h>
|
---|
[6401] | 32 | #include <odinapi.h>
|
---|
[6374] | 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>
|
---|
[6857] | 38 | #include "ordinals.h"
|
---|
[6374] | 39 |
|
---|
| 40 | BOOL fVersionWarp3 = FALSE;
|
---|
[6401] | 41 | static HKEY hKeyClassesRoot = 0;
|
---|
| 42 | static HKEY hKeyCurrentUser = 0;
|
---|
| 43 | static HKEY hKeyLocalMachine = 0;
|
---|
| 44 | static HKEY hKeyUsers = 0;
|
---|
[6374] | 45 |
|
---|
[6443] | 46 | static HMODULE hDllAdvapi32 = 0;
|
---|
[6450] | 47 | static HMODULE hDllGdi32 = 0;
|
---|
[6443] | 48 |
|
---|
[6374] | 49 | #ifdef __IBMCPP__
|
---|
| 50 | extern "C" {
|
---|
| 51 |
|
---|
[21916] | 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 |
|
---|
[6374] | 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 | }
|
---|
[6401] | 95 |
|
---|
[6374] | 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 | /****************************************************************************/
|
---|
[21916] | 104 | ULONG SYSTEM _DLL_InitTerm(ULONG hModule, ULONG ulFlag)
|
---|
[6374] | 105 | {
|
---|
| 106 | size_t i;
|
---|
| 107 | APIRET rc;
|
---|
| 108 | ULONG version[2];
|
---|
[6414] | 109 | static BOOL fInit = FALSE, fExit = FALSE;
|
---|
[6374] | 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 :
|
---|
[6414] | 119 | {
|
---|
[6374] | 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 | /*******************************************************************/
|
---|
[6413] | 141 | rc = DosExitList(EXITLIST_KERNEL32|EXLST_ADD, cleanup);
|
---|
[6374] | 142 | if(rc)
|
---|
| 143 | return 0UL;
|
---|
| 144 |
|
---|
[6414] | 145 | char szErrName[CCHMAXPATH];
|
---|
[21581] | 146 | rc = DosLoadModule(szErrName, sizeof(szErrName), "XXODIN32", &hModule);
|
---|
[6414] | 147 | if(rc != 0) {
|
---|
| 148 | return 0;
|
---|
| 149 | }
|
---|
[6374] | 150 |
|
---|
[6401] | 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 |
|
---|
[6472] | 168 | SetCustomBuildName("NTDLL.DLL", 0);
|
---|
[6459] | 169 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
---|
| 170 | return 0UL;
|
---|
| 171 |
|
---|
[6472] | 172 | SetCustomBuildName("KERNEL32.DLL", ORDINALBASE_KERNEL32);
|
---|
[6374] | 173 | rc = inittermKernel32(hModule, ulFlag);
|
---|
[21916] | 174 | if(rc == 0)
|
---|
[6401] | 175 | return 0UL;
|
---|
[6374] | 176 |
|
---|
[6472] | 177 | SetCustomBuildName("USER32.DLL", ORDINALBASE_USER32);
|
---|
[6374] | 178 | rc = inittermUser32(hModule, ulFlag);
|
---|
[21916] | 179 | if(rc == 0)
|
---|
[6374] | 180 | return 0UL;
|
---|
| 181 |
|
---|
[6472] | 182 | SetCustomBuildName("GDI32.DLL", ORDINALBASE_GDI32);
|
---|
[6459] | 183 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
---|
| 184 | return 0UL;
|
---|
[6450] | 185 |
|
---|
[6472] | 186 | SetCustomBuildName("ADVAPI32.DLL", 0);
|
---|
[6459] | 187 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
---|
| 188 | return 0UL;
|
---|
[6450] | 189 |
|
---|
[21916] | 190 | SetCustomBuildName("VERSION.DLL", 0);
|
---|
[6407] | 191 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
---|
| 192 | return 0UL;
|
---|
| 193 |
|
---|
[6472] | 194 | SetCustomBuildName("WSOCK32.DLL", ORDINALBASE_WSOCK32);
|
---|
[6401] | 195 | rc = inittermWsock32(hModule, ulFlag);
|
---|
[21916] | 196 | if(rc == 0)
|
---|
[6401] | 197 | return 0UL;
|
---|
| 198 |
|
---|
[6472] | 199 | SetCustomBuildName("WINMM.DLL", 0);
|
---|
[6374] | 200 | rc = inittermWinmm(hModule, ulFlag);
|
---|
[21916] | 201 | if(rc == 0)
|
---|
[6374] | 202 | return 0UL;
|
---|
| 203 |
|
---|
[6472] | 204 | SetCustomBuildName("RPCRT4.DLL", 0);
|
---|
[6374] | 205 | rc = inittermRpcrt4(hModule, ulFlag);
|
---|
[21916] | 206 | if(rc == 0)
|
---|
[6374] | 207 | return 0UL;
|
---|
| 208 |
|
---|
[6472] | 209 | SetCustomBuildName("OLE32.DLL", ORDINALBASE_OLE32);
|
---|
[6374] | 210 | rc = inittermOle32(hModule, ulFlag);
|
---|
[21916] | 211 | if(rc == 0)
|
---|
[6374] | 212 | return 0UL;
|
---|
| 213 |
|
---|
[6472] | 214 | SetCustomBuildName("COMCTL32.DLL", ORDINALBASE_COMCTL32);
|
---|
[6374] | 215 | rc = inittermComctl32(hModule, ulFlag);
|
---|
[21916] | 216 | if(rc == 0)
|
---|
[6374] | 217 | return 0UL;
|
---|
| 218 |
|
---|
[6472] | 219 | SetCustomBuildName("SHLWAPI.DLL", ORDINALBASE_SHLWAPI);
|
---|
| 220 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
---|
| 221 | return 0UL;
|
---|
| 222 |
|
---|
| 223 | SetCustomBuildName("SHELL32.DLL", ORDINALBASE_SHELL32);
|
---|
[6374] | 224 | rc = inittermShell32(hModule, ulFlag);
|
---|
[21916] | 225 | if(rc == 0)
|
---|
[6374] | 226 | return 0UL;
|
---|
| 227 |
|
---|
[6472] | 228 | SetCustomBuildName("COMDLG32.DLL", 0);
|
---|
[6374] | 229 | rc = inittermComdlg32(hModule, ulFlag);
|
---|
[21916] | 230 | if(rc == 0)
|
---|
[6374] | 231 | return 0UL;
|
---|
| 232 |
|
---|
[6587] | 233 | SetCustomBuildName("RICHED32.DLL", 0);
|
---|
| 234 | rc = inittermRiched32(hModule, ulFlag);
|
---|
[21916] | 235 | if(rc == 0)
|
---|
[6587] | 236 | return 0UL;
|
---|
[21916] | 237 |
|
---|
[6472] | 238 | SetCustomBuildName(NULL, 0);
|
---|
[6374] | 239 | break;
|
---|
[6414] | 240 | }
|
---|
| 241 |
|
---|
[6374] | 242 | case 1 :
|
---|
[6414] | 243 | {
|
---|
[6374] | 244 | inittermComdlg32(hModule, ulFlag);
|
---|
| 245 | inittermShell32(hModule, ulFlag);
|
---|
| 246 | inittermComctl32(hModule, ulFlag);
|
---|
| 247 | inittermOle32(hModule, ulFlag);
|
---|
| 248 | inittermRpcrt4(hModule, ulFlag);
|
---|
| 249 | inittermWinmm(hModule, ulFlag);
|
---|
[6401] | 250 | inittermWsock32(hModule, ulFlag);
|
---|
[6374] | 251 | inittermUser32(hModule, ulFlag);
|
---|
| 252 | inittermKernel32(hModule, ulFlag);
|
---|
| 253 | break;
|
---|
[6414] | 254 | }
|
---|
[6374] | 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 | //******************************************************************************
|
---|
[6412] | 278 | ULONG APIENTRY O32__DLL_InitTerm(ULONG handle, ULONG flag);
|
---|
| 279 | //******************************************************************************
|
---|
[21916] | 280 | BOOL APIENTRY InitializeKernel32()
|
---|
[6412] | 281 | {
|
---|
| 282 | HMODULE hModule;
|
---|
| 283 |
|
---|
[21426] | 284 | DosQueryModuleHandleStrict("WGSS50", &hModule);
|
---|
[21916] | 285 | return O32__DLL_InitTerm(hModule, 0) != 0;
|
---|
[6412] | 286 | }
|
---|
| 287 | //******************************************************************************
|
---|
| 288 | //******************************************************************************
|
---|
[6374] | 289 | #else
|
---|
| 290 | #error message("compiler is not supported");
|
---|
| 291 | #endif
|
---|