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

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

created

File size: 6.1 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 <win32type.h>
34#include <winconst.h>
35#include <odinlx.h>
36#include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
37#include <initdll.h>
38#include <exitlist.h>
39
40BOOL fVersionWarp3 = FALSE;
41
42#ifdef __IBMCPP__
43extern "C" {
44
45/*-------------------------------------------------------------------*/
46/* A clean up routine registered with DosExitList must be used if */
47/* runtime calls are required and the runtime is dynamically linked. */
48/* This will guarantee that this clean up routine is run before the */
49/* library DLL is terminated. */
50/*-------------------------------------------------------------------*/
51static void APIENTRY cleanup(ULONG reason);
52}
53/****************************************************************************/
54/* _DLL_InitTerm is the function that gets called by the operating system */
55/* loader when it loads and frees this DLL for each process that accesses */
56/* this DLL. However, it only gets called the first time the DLL is loaded */
57/* and the last time it is freed for a particular process. The system */
58/* linkage convention MUST be used because the operating system loader is */
59/* calling this function. */
60/****************************************************************************/
61ULONG DLLENTRYPOINT_CCONV DLLENTRYPOINT_NAME(ULONG hModule, ULONG ulFlag)
62{
63 size_t i;
64 APIRET rc;
65 ULONG version[2];
66
67 /*-------------------------------------------------------------------------*/
68 /* If ulFlag is zero then the DLL is being loaded so initialization should */
69 /* be performed. If ulFlag is 1 then the DLL is being freed so */
70 /* termination should be performed. */
71 /*-------------------------------------------------------------------------*/
72
73 switch (ulFlag) {
74 case 0 :
75 /*******************************************************************/
76 /* The C run-time environment initialization function must be */
77 /* called before any calls to C run-time functions that are not */
78 /* inlined. */
79 /*******************************************************************/
80
81 if (_CRT_init() == -1)
82 return 0UL;
83 ctordtorInit();
84
85 rc = DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, version, sizeof(version));
86 if(rc == 0){
87 if(version[0] >= 20 && version[1] <= 30) {
88 fVersionWarp3 = TRUE;
89 }
90 }
91
92 /*******************************************************************/
93 /* A DosExitList routine must be used to clean up if runtime calls */
94 /* are required and the runtime is dynamically linked. */
95 /*******************************************************************/
96 rc = DosExitList(EXITLIST_ODINCRT|EXLST_ADD, cleanup);
97 if(rc)
98 return 0UL;
99
100 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
101
102 rc = inittermKernel32(hModule, ulFlag);
103 if(rc == 0)
104 return 0UL;
105
106 rc = inittermUser32(hModule, ulFlag);
107 if(rc == 0)
108 return 0UL;
109
110 rc = inittermWinmm(hModule, ulFlag);
111 if(rc == 0)
112 return 0UL;
113
114 rc = inittermRpcrt4(hModule, ulFlag);
115 if(rc == 0)
116 return 0UL;
117
118 rc = inittermOle32(hModule, ulFlag);
119 if(rc == 0)
120 return 0UL;
121
122 rc = inittermComctl32(hModule, ulFlag);
123 if(rc == 0)
124 return 0UL;
125
126 rc = inittermShell32(hModule, ulFlag);
127 if(rc == 0)
128 return 0UL;
129
130 rc = inittermComdlg32(hModule, ulFlag);
131 if(rc == 0)
132 return 0UL;
133
134 break;
135 case 1 :
136 inittermComdlg32(hModule, ulFlag);
137 inittermShell32(hModule, ulFlag);
138 inittermComctl32(hModule, ulFlag);
139 inittermOle32(hModule, ulFlag);
140 inittermRpcrt4(hModule, ulFlag);
141 inittermWinmm(hModule, ulFlag);
142 inittermUser32(hModule, ulFlag);
143 inittermKernel32(hModule, ulFlag);
144 break;
145
146 default :
147 return 0UL;
148 }
149
150 /***********************************************************/
151 /* A non-zero value must be returned to indicate success. */
152 /***********************************************************/
153 return 1UL;
154}
155//******************************************************************************
156//******************************************************************************
157static void APIENTRY cleanup(ULONG ulReason)
158{
159 cleanupUser32(ulReason);
160 cleanupKernel32(ulReason);
161 ctordtorTerm();
162 _CRT_term();
163 DosExitList(EXLST_EXIT, cleanup);
164 return ;
165}
166//******************************************************************************
167//******************************************************************************
168#else
169#error message("compiler is not supported");
170#endif
Note: See TracBrowser for help on using the repository browser.