source: trunk/src/odincrt/initterm.cpp@ 5280

Last change on this file since 5280 was 5135, checked in by sandervl, 25 years ago

VAC 3.6.5 bug workaround

File size: 5.2 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_DOSPROCESS
27#include <os2wrap.h> //Odin32 OS/2 api wrappers
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <odin.h>
32#include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
33#include <exitlist.h>
34#include <initdll.h>
35
36#ifdef __IBMCPP__
37extern "C" {
38
39/*-------------------------------------------------------------------*/
40/* A clean up routine registered with DosExitList must be used if */
41/* runtime calls are required and the runtime is dynamically linked. */
42/* This will guarantee that this clean up routine is run before the */
43/* library DLL is terminated. */
44/*-------------------------------------------------------------------*/
45static void APIENTRY cleanup(ULONG reason);
46}
47
48/****************************************************************************/
49/* _DLL_InitTerm is the function that gets called by the operating system */
50/* loader when it loads and frees this DLL for each process that accesses */
51/* this DLL. However, it only gets called the first time the DLL is loaded */
52/* and the last time it is freed for a particular process. The system */
53/* linkage convention MUST be used because the operating system loader is */
54/* calling this function. */
55/****************************************************************************/
56unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
57 ulFlag)
58{
59 APIRET rc;
60
61 /*-------------------------------------------------------------------------*/
62 /* If ulFlag is zero then the DLL is being loaded so initialization should */
63 /* be performed. If ulFlag is 1 then the DLL is being freed so */
64 /* termination should be performed. */
65 /*-------------------------------------------------------------------------*/
66
67 switch (ulFlag) {
68 case 0 :
69
70 /*******************************************************************/
71 /* The C run-time environment initialization function must be */
72 /* called before any calls to C run-time functions that are not */
73 /* inlined. */
74 /*******************************************************************/
75
76 if (_CRT_init() == -1)
77 return 0UL;
78 ctordtorInit();
79
80 /*******************************************************************/
81 /* A DosExitList routine must be used to clean up if runtime calls */
82 /* are required and the runtime is dynamically linked. */
83 /*******************************************************************/
84
85 rc = DosExitList(EXITLIST_ODINCRT|EXLST_ADD, cleanup);
86 if(rc)
87 return 0UL;
88 #if 1 /*
89 * Experimental console hack. Sets apptype to PM anyhow.
90 * First Dll to be initiated should now allways be OdinCrt!
91 * So include odincrt first!
92 */
93 PPIB pPIB;
94 PTIB pTIB;
95 rc = DosGetInfoBlocks(&pTIB, &pPIB);
96 if (rc != NO_ERROR)
97 return 0UL;
98 pPIB->pib_ultype = 3;
99 #endif
100 break;
101 case 1 :
102 break;
103 default :
104 return 0UL;
105 }
106
107 /***********************************************************/
108 /* A non-zero value must be returned to indicate success. */
109 /***********************************************************/
110 return 1UL;
111}
112
113
114static void APIENTRY cleanup(ULONG ulReason)
115{
116 ctordtorTerm();
117 _CRT_term();
118 DosExitList(EXLST_EXIT, cleanup);
119 return ;
120}
121
122#elif defined(__WATCOM_CPLUSPLUS__)
123
124/*
125 * Watcom dll init and term routines.
126 */
127
128int __dll_initialize(unsigned long hModule, unsigned long ulFlag)
129{
130 APIRET rc;
131 #if 1 /*
132 * Experimental console hack. Sets apptype to PM anyhow.
133 * First Dll to be initiated should now allways be OdinCrt!
134 * So include odincrt first!
135 */
136 PPIB pPIB;
137 PTIB pTIB;
138 rc = DosGetInfoBlocks(&pTIB, &pPIB);
139 if (rc != NO_ERROR)
140 return 0UL;
141 pPIB->pib_ultype = 3;
142 #endif
143 return 1;
144}
145
146int __dll_terminate(unsigned long hModule, unsigned long ulFlag)
147{
148 return 1;
149}
150
151#else
152#error message("compiler is not supported");
153#endif
154
Note: See TracBrowser for help on using the repository browser.