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

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

custom build fixes

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