source: trunk/src/custombuild/initterm.cpp@ 6857

Last change on this file since 6857 was 6857, checked in by sandervl, 24 years ago

custom dll updates

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