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

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

add gdi32 registration call

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