source: branches/swt/src/custombuild/initterm.cpp@ 22145

Last change on this file since 22145 was 22101, checked in by rousseau, 10 years ago

Cloned 'uxtheme' module to 'usp10'

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