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

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

dummy module object for advapi32

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