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

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

custom build updates

File size: 7.7 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
74 /*-------------------------------------------------------------------------*/
75 /* If ulFlag is zero then the DLL is being loaded so initialization should */
76 /* be performed. If ulFlag is 1 then the DLL is being freed so */
77 /* termination should be performed. */
78 /*-------------------------------------------------------------------------*/
79
80 switch (ulFlag) {
81 case 0 :
82 /*******************************************************************/
83 /* The C run-time environment initialization function must be */
84 /* called before any calls to C run-time functions that are not */
85 /* inlined. */
86 /*******************************************************************/
87
88 if (_CRT_init() == -1)
89 return 0UL;
90 ctordtorInit();
91
92 rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
93 if(rc == 0){
94 if(version[0] >= 20 && version[1] <= 30) {
95 fVersionWarp3 = TRUE;
96 }
97 }
98
99 /*******************************************************************/
100 /* A DosExitList routine must be used to clean up if runtime calls */
101 /* are required and the runtime is dynamically linked. */
102 /*******************************************************************/
103 rc = DosExitList(EXITLIST_ODINCRT|EXLST_ADD, cleanup);
104 if(rc)
105 return 0UL;
106
107 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
108
109 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_ClassesRoot",&hKeyClassesRoot)!=ERROR_SUCCESS_W) {
110 return 0;
111 }
112 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_CurrentUser",&hKeyCurrentUser)!=ERROR_SUCCESS_W) {
113 return 0;
114 }
115 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_LocalMachine",&hKeyLocalMachine)!=ERROR_SUCCESS_W) {
116 return 0;
117 }
118 if(RegCreateKeyA(HKEY_LOCAL_MACHINE,"Software\\XXOdin32\\REGROOT_HKEY_Users",&hKeyUsers)!=ERROR_SUCCESS_W) {
119 return 0;
120 }
121 SetRegistryRootKey(HKEY_CLASSES_ROOT, hKeyClassesRoot);
122 SetRegistryRootKey(HKEY_CURRENT_USER, hKeyCurrentUser);
123 SetRegistryRootKey(HKEY_LOCAL_MACHINE, hKeyLocalMachine);
124 SetRegistryRootKey(HKEY_USERS, hKeyUsers);
125
126 SetCustomBuildName("KERNEL32.DLL");
127 rc = inittermKernel32(hModule, ulFlag);
128 if(rc == 0)
129 return 0UL;
130
131 SetCustomBuildName("USER32.DLL");
132 rc = inittermUser32(hModule, ulFlag);
133 if(rc == 0)
134 return 0UL;
135
136 SetCustomBuildName("WSOCK32.DLL");
137 rc = inittermWsock32(hModule, ulFlag);
138 if(rc == 0)
139 return 0UL;
140
141 SetCustomBuildName("WINMM.DLL");
142 rc = inittermWinmm(hModule, ulFlag);
143 if(rc == 0)
144 return 0UL;
145
146 SetCustomBuildName("RPCRT4.DLL");
147 rc = inittermRpcrt4(hModule, ulFlag);
148 if(rc == 0)
149 return 0UL;
150
151 SetCustomBuildName("OLE32.DLL");
152 rc = inittermOle32(hModule, ulFlag);
153 if(rc == 0)
154 return 0UL;
155
156 SetCustomBuildName("COMCTL32.DLL");
157 rc = inittermComctl32(hModule, ulFlag);
158 if(rc == 0)
159 return 0UL;
160
161 SetCustomBuildName("SHELL32.DLL");
162 rc = inittermShell32(hModule, ulFlag);
163 if(rc == 0)
164 return 0UL;
165
166 SetCustomBuildName("COMDLG32.DLL");
167 rc = inittermComdlg32(hModule, ulFlag);
168 if(rc == 0)
169 return 0UL;
170
171 SetCustomBuildName(NULL);
172 break;
173 case 1 :
174 inittermComdlg32(hModule, ulFlag);
175 inittermShell32(hModule, ulFlag);
176 inittermComctl32(hModule, ulFlag);
177 inittermOle32(hModule, ulFlag);
178 inittermRpcrt4(hModule, ulFlag);
179 inittermWinmm(hModule, ulFlag);
180 inittermWsock32(hModule, ulFlag);
181 inittermUser32(hModule, ulFlag);
182 inittermKernel32(hModule, ulFlag);
183 break;
184
185 default :
186 return 0UL;
187 }
188
189 /***********************************************************/
190 /* A non-zero value must be returned to indicate success. */
191 /***********************************************************/
192 return 1UL;
193}
194//******************************************************************************
195//******************************************************************************
196static void APIENTRY cleanup(ULONG ulReason)
197{
198 cleanupUser32(ulReason);
199 cleanupKernel32(ulReason);
200 ctordtorTerm();
201 _CRT_term();
202 DosExitList(EXLST_EXIT, cleanup);
203 return ;
204}
205//******************************************************************************
206//******************************************************************************
207#else
208#error message("compiler is not supported");
209#endif
Note: See TracBrowser for help on using the repository browser.