| 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 | /*-------------------------------------------------------------*/
|
|---|
| 13 | /* INITERM.C -- Source for a custom dynamic link library */
|
|---|
| 14 | /* initialization and termination (_DLL_InitTerm) */
|
|---|
| 15 | /* function. */
|
|---|
| 16 | /* */
|
|---|
| 17 | /* When called to perform initialization, this sample function */
|
|---|
| 18 | /* gets storage for an array of integers, and initializes its */
|
|---|
| 19 | /* elements with random integers. At termination time, it */
|
|---|
| 20 | /* frees the array. Substitute your own special processing. */
|
|---|
| 21 | /*-------------------------------------------------------------*/
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | /* Include files */
|
|---|
| 25 | #define INCL_DOSMODULEMGR
|
|---|
| 26 | #define INCL_DOSMISC
|
|---|
| 27 | #define INCL_DOSPROCESS
|
|---|
| 28 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 29 | #include <stdlib.h>
|
|---|
| 30 | #include <stdio.h>
|
|---|
| 31 | #include <string.h>
|
|---|
| 32 | #include <odin.h>
|
|---|
| 33 | #include <win32api.h>
|
|---|
| 34 | #include <win32type.h>
|
|---|
| 35 | #include <odinapi.h>
|
|---|
| 36 | #include <winconst.h>
|
|---|
| 37 | #include <odinlx.h>
|
|---|
| 38 | #include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
|
|---|
| 39 | #include <initdll.h>
|
|---|
| 40 | #include <exitlist.h>
|
|---|
| 41 |
|
|---|
| 42 | BOOL fVersionWarp3 = FALSE;
|
|---|
| 43 | static HKEY hKeyClassesRoot = 0;
|
|---|
| 44 | static HKEY hKeyCurrentUser = 0;
|
|---|
| 45 | static HKEY hKeyLocalMachine = 0;
|
|---|
| 46 | static HKEY hKeyUsers = 0;
|
|---|
| 47 |
|
|---|
| 48 | static HMODULE hDllAdvapi32 = 0;
|
|---|
| 49 | static HMODULE hDllGdi32 = 0;
|
|---|
| 50 |
|
|---|
| 51 | #ifdef __IBMCPP__
|
|---|
| 52 | extern "C" {
|
|---|
| 53 |
|
|---|
| 54 | /*-------------------------------------------------------------------*/
|
|---|
| 55 | /* A clean up routine registered with DosExitList must be used if */
|
|---|
| 56 | /* runtime calls are required and the runtime is dynamically linked. */
|
|---|
| 57 | /* This will guarantee that this clean up routine is run before the */
|
|---|
| 58 | /* library DLL is terminated. */
|
|---|
| 59 | /*-------------------------------------------------------------------*/
|
|---|
| 60 | static void APIENTRY cleanup(ULONG reason);
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | /****************************************************************************/
|
|---|
| 64 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
|---|
| 65 | /* loader when it loads and frees this DLL for each process that accesses */
|
|---|
| 66 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
|---|
| 67 | /* and the last time it is freed for a particular process. The system */
|
|---|
| 68 | /* linkage convention MUST be used because the operating system loader is */
|
|---|
| 69 | /* calling this function. */
|
|---|
| 70 | /****************************************************************************/
|
|---|
| 71 | ULONG DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(ULONG hModule, ULONG ulFlag)
|
|---|
| 72 | {
|
|---|
| 73 | size_t i;
|
|---|
| 74 | APIRET rc;
|
|---|
| 75 | ULONG version[2];
|
|---|
| 76 | static BOOL fInit = FALSE, fExit = FALSE;
|
|---|
| 77 |
|
|---|
| 78 | /*-------------------------------------------------------------------------*/
|
|---|
| 79 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
|---|
| 80 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
|---|
| 81 | /* termination should be performed. */
|
|---|
| 82 | /*-------------------------------------------------------------------------*/
|
|---|
| 83 |
|
|---|
| 84 | switch (ulFlag) {
|
|---|
| 85 | case 0 :
|
|---|
| 86 | {
|
|---|
| 87 | /*******************************************************************/
|
|---|
| 88 | /* The C run-time environment initialization function must be */
|
|---|
| 89 | /* called before any calls to C run-time functions that are not */
|
|---|
| 90 | /* inlined. */
|
|---|
| 91 | /*******************************************************************/
|
|---|
| 92 |
|
|---|
| 93 | if (_CRT_init() == -1)
|
|---|
| 94 | return 0UL;
|
|---|
| 95 | ctordtorInit();
|
|---|
| 96 |
|
|---|
| 97 | rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
|
|---|
| 98 | if(rc == 0){
|
|---|
| 99 | if(version[0] >= 20 && version[1] <= 30) {
|
|---|
| 100 | fVersionWarp3 = TRUE;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /*******************************************************************/
|
|---|
| 105 | /* A DosExitList routine must be used to clean up if runtime calls */
|
|---|
| 106 | /* are required and the runtime is dynamically linked. */
|
|---|
| 107 | /*******************************************************************/
|
|---|
| 108 | rc = DosExitList(EXITLIST_KERNEL32|EXLST_ADD, cleanup);
|
|---|
| 109 | if(rc)
|
|---|
| 110 | return 0UL;
|
|---|
| 111 |
|
|---|
| 112 | char szErrName[CCHMAXPATH];
|
|---|
| 113 | rc = DosLoadModule(szErrName, sizeof(szErrName), "XXODIN32.DLL", &hModule);
|
|---|
| 114 | if(rc != 0) {
|
|---|
| 115 | return 0;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_ClassesRoot",&hKeyClassesRoot)!=ERROR_SUCCESS_W) {
|
|---|
| 119 | return 0;
|
|---|
| 120 | }
|
|---|
| 121 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_CurrentUser",&hKeyCurrentUser)!=ERROR_SUCCESS_W) {
|
|---|
| 122 | return 0;
|
|---|
| 123 | }
|
|---|
| 124 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_LocalMachine",&hKeyLocalMachine)!=ERROR_SUCCESS_W) {
|
|---|
| 125 | return 0;
|
|---|
| 126 | }
|
|---|
| 127 | if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_Users",&hKeyUsers)!=ERROR_SUCCESS_W) {
|
|---|
| 128 | return 0;
|
|---|
| 129 | }
|
|---|
| 130 | SetRegistryRootKey(HKEY_CLASSES_ROOT, hKeyClassesRoot);
|
|---|
| 131 | SetRegistryRootKey(HKEY_CURRENT_USER, hKeyCurrentUser);
|
|---|
| 132 | SetRegistryRootKey(HKEY_LOCAL_MACHINE, hKeyLocalMachine);
|
|---|
| 133 | SetRegistryRootKey(HKEY_USERS, hKeyUsers);
|
|---|
| 134 |
|
|---|
| 135 | SetCustomBuildName("NTDLL.DLL", 0);
|
|---|
| 136 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 137 | return 0UL;
|
|---|
| 138 |
|
|---|
| 139 | SetCustomBuildName("KERNEL32.DLL", ORDINALBASE_KERNEL32);
|
|---|
| 140 | rc = inittermKernel32(hModule, ulFlag);
|
|---|
| 141 | if(rc == 0)
|
|---|
| 142 | return 0UL;
|
|---|
| 143 |
|
|---|
| 144 | SetCustomBuildName("USER32.DLL", ORDINALBASE_USER32);
|
|---|
| 145 | rc = inittermUser32(hModule, ulFlag);
|
|---|
| 146 | if(rc == 0)
|
|---|
| 147 | return 0UL;
|
|---|
| 148 |
|
|---|
| 149 | SetCustomBuildName("GDI32.DLL", ORDINALBASE_GDI32);
|
|---|
| 150 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 151 | return 0UL;
|
|---|
| 152 |
|
|---|
| 153 | SetCustomBuildName("ADVAPI32.DLL", 0);
|
|---|
| 154 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 155 | return 0UL;
|
|---|
| 156 |
|
|---|
| 157 | SetCustomBuildName("VERSION.DLL", 0);
|
|---|
| 158 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 159 | return 0UL;
|
|---|
| 160 |
|
|---|
| 161 | SetCustomBuildName("WSOCK32.DLL", ORDINALBASE_WSOCK32);
|
|---|
| 162 | rc = inittermWsock32(hModule, ulFlag);
|
|---|
| 163 | if(rc == 0)
|
|---|
| 164 | return 0UL;
|
|---|
| 165 |
|
|---|
| 166 | SetCustomBuildName("WINMM.DLL", 0);
|
|---|
| 167 | rc = inittermWinmm(hModule, ulFlag);
|
|---|
| 168 | if(rc == 0)
|
|---|
| 169 | return 0UL;
|
|---|
| 170 |
|
|---|
| 171 | SetCustomBuildName("RPCRT4.DLL", 0);
|
|---|
| 172 | rc = inittermRpcrt4(hModule, ulFlag);
|
|---|
| 173 | if(rc == 0)
|
|---|
| 174 | return 0UL;
|
|---|
| 175 |
|
|---|
| 176 | SetCustomBuildName("OLE32.DLL", ORDINALBASE_OLE32);
|
|---|
| 177 | rc = inittermOle32(hModule, ulFlag);
|
|---|
| 178 | if(rc == 0)
|
|---|
| 179 | return 0UL;
|
|---|
| 180 |
|
|---|
| 181 | SetCustomBuildName("COMCTL32.DLL", ORDINALBASE_COMCTL32);
|
|---|
| 182 | rc = inittermComctl32(hModule, ulFlag);
|
|---|
| 183 | if(rc == 0)
|
|---|
| 184 | return 0UL;
|
|---|
| 185 |
|
|---|
| 186 | SetCustomBuildName("SHLWAPI.DLL", ORDINALBASE_SHLWAPI);
|
|---|
| 187 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
|---|
| 188 | return 0UL;
|
|---|
| 189 |
|
|---|
| 190 | SetCustomBuildName("SHELL32.DLL", ORDINALBASE_SHELL32);
|
|---|
| 191 | rc = inittermShell32(hModule, ulFlag);
|
|---|
| 192 | if(rc == 0)
|
|---|
| 193 | return 0UL;
|
|---|
| 194 |
|
|---|
| 195 | SetCustomBuildName("COMDLG32.DLL", 0);
|
|---|
| 196 | rc = inittermComdlg32(hModule, ulFlag);
|
|---|
| 197 | if(rc == 0)
|
|---|
| 198 | return 0UL;
|
|---|
| 199 |
|
|---|
| 200 | SetCustomBuildName("RICHED32.DLL", 0);
|
|---|
| 201 | rc = inittermRiched32(hModule, ulFlag);
|
|---|
| 202 | if(rc == 0)
|
|---|
| 203 | return 0UL;
|
|---|
| 204 |
|
|---|
| 205 | SetCustomBuildName(NULL, 0);
|
|---|
| 206 | break;
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | case 1 :
|
|---|
| 210 | {
|
|---|
| 211 | inittermComdlg32(hModule, ulFlag);
|
|---|
| 212 | inittermShell32(hModule, ulFlag);
|
|---|
| 213 | inittermComctl32(hModule, ulFlag);
|
|---|
| 214 | inittermOle32(hModule, ulFlag);
|
|---|
| 215 | inittermRpcrt4(hModule, ulFlag);
|
|---|
| 216 | inittermWinmm(hModule, ulFlag);
|
|---|
| 217 | inittermWsock32(hModule, ulFlag);
|
|---|
| 218 | inittermUser32(hModule, ulFlag);
|
|---|
| 219 | inittermKernel32(hModule, ulFlag);
|
|---|
| 220 | break;
|
|---|
| 221 | }
|
|---|
| 222 |
|
|---|
| 223 | default :
|
|---|
| 224 | return 0UL;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | /***********************************************************/
|
|---|
| 228 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 229 | /***********************************************************/
|
|---|
| 230 | return 1UL;
|
|---|
| 231 | }
|
|---|
| 232 | //******************************************************************************
|
|---|
| 233 | //******************************************************************************
|
|---|
| 234 | static void APIENTRY cleanup(ULONG ulReason)
|
|---|
| 235 | {
|
|---|
| 236 | cleanupUser32(ulReason);
|
|---|
| 237 | cleanupKernel32(ulReason);
|
|---|
| 238 | ctordtorTerm();
|
|---|
| 239 | _CRT_term();
|
|---|
| 240 | DosExitList(EXLST_EXIT, cleanup);
|
|---|
| 241 | return ;
|
|---|
| 242 | }
|
|---|
| 243 | //******************************************************************************
|
|---|
| 244 | //******************************************************************************
|
|---|
| 245 | ULONG APIENTRY O32__DLL_InitTerm(ULONG handle, ULONG flag);
|
|---|
| 246 | //******************************************************************************
|
|---|
| 247 | ULONG APIENTRY InitializeKernel32()
|
|---|
| 248 | {
|
|---|
| 249 | HMODULE hModule;
|
|---|
| 250 |
|
|---|
| 251 | DosQueryModuleHandle("WGSS50", &hModule);
|
|---|
| 252 | O32__DLL_InitTerm(hModule, 0);
|
|---|
| 253 | DosQueryModuleHandle("XXODIN32", &hModule);
|
|---|
| 254 | return inittermKernel32(hModule, 0);
|
|---|
| 255 | }
|
|---|
| 256 | //******************************************************************************
|
|---|
| 257 | //******************************************************************************
|
|---|
| 258 | #else
|
|---|
| 259 | #error message("compiler is not supported");
|
|---|
| 260 | #endif
|
|---|