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 |
|
---|
42 | BOOL fVersionWarp3 = FALSE;
|
---|
43 | static HKEY hKeyClassesRoot = 0;
|
---|
44 | static HKEY hKeyCurrentUser = 0;
|
---|
45 | static HKEY hKeyLocalMachine = 0;
|
---|
46 | static HKEY hKeyUsers = 0;
|
---|
47 |
|
---|
48 | #ifdef __IBMCPP__
|
---|
49 | extern "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 | /*-------------------------------------------------------------------*/
|
---|
57 | static 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 | /****************************************************************************/
|
---|
68 | ULONG 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("VERSION.DLL");
|
---|
137 | if(RegisterLxDll(hModule, NULL, (PVOID)NULL) == 0)
|
---|
138 | return 0UL;
|
---|
139 |
|
---|
140 | SetCustomBuildName("WSOCK32.DLL");
|
---|
141 | rc = inittermWsock32(hModule, ulFlag);
|
---|
142 | if(rc == 0)
|
---|
143 | return 0UL;
|
---|
144 |
|
---|
145 | SetCustomBuildName("WINMM.DLL");
|
---|
146 | rc = inittermWinmm(hModule, ulFlag);
|
---|
147 | if(rc == 0)
|
---|
148 | return 0UL;
|
---|
149 |
|
---|
150 | SetCustomBuildName("RPCRT4.DLL");
|
---|
151 | rc = inittermRpcrt4(hModule, ulFlag);
|
---|
152 | if(rc == 0)
|
---|
153 | return 0UL;
|
---|
154 |
|
---|
155 | SetCustomBuildName("OLE32.DLL");
|
---|
156 | rc = inittermOle32(hModule, ulFlag);
|
---|
157 | if(rc == 0)
|
---|
158 | return 0UL;
|
---|
159 |
|
---|
160 | SetCustomBuildName("COMCTL32.DLL");
|
---|
161 | rc = inittermComctl32(hModule, ulFlag);
|
---|
162 | if(rc == 0)
|
---|
163 | return 0UL;
|
---|
164 |
|
---|
165 | SetCustomBuildName("SHELL32.DLL");
|
---|
166 | rc = inittermShell32(hModule, ulFlag);
|
---|
167 | if(rc == 0)
|
---|
168 | return 0UL;
|
---|
169 |
|
---|
170 | SetCustomBuildName("COMDLG32.DLL");
|
---|
171 | rc = inittermComdlg32(hModule, ulFlag);
|
---|
172 | if(rc == 0)
|
---|
173 | return 0UL;
|
---|
174 |
|
---|
175 | SetCustomBuildName(NULL);
|
---|
176 | break;
|
---|
177 | case 1 :
|
---|
178 | inittermComdlg32(hModule, ulFlag);
|
---|
179 | inittermShell32(hModule, ulFlag);
|
---|
180 | inittermComctl32(hModule, ulFlag);
|
---|
181 | inittermOle32(hModule, ulFlag);
|
---|
182 | inittermRpcrt4(hModule, ulFlag);
|
---|
183 | inittermWinmm(hModule, ulFlag);
|
---|
184 | inittermWsock32(hModule, ulFlag);
|
---|
185 | inittermUser32(hModule, ulFlag);
|
---|
186 | inittermKernel32(hModule, ulFlag);
|
---|
187 | break;
|
---|
188 |
|
---|
189 | default :
|
---|
190 | return 0UL;
|
---|
191 | }
|
---|
192 |
|
---|
193 | /***********************************************************/
|
---|
194 | /* A non-zero value must be returned to indicate success. */
|
---|
195 | /***********************************************************/
|
---|
196 | return 1UL;
|
---|
197 | }
|
---|
198 | //******************************************************************************
|
---|
199 | //******************************************************************************
|
---|
200 | static void APIENTRY cleanup(ULONG ulReason)
|
---|
201 | {
|
---|
202 | cleanupUser32(ulReason);
|
---|
203 | cleanupKernel32(ulReason);
|
---|
204 | ctordtorTerm();
|
---|
205 | _CRT_term();
|
---|
206 | DosExitList(EXLST_EXIT, cleanup);
|
---|
207 | return ;
|
---|
208 | }
|
---|
209 | //******************************************************************************
|
---|
210 | //******************************************************************************
|
---|
211 | #else
|
---|
212 | #error message("compiler is not supported");
|
---|
213 | #endif
|
---|