source: trunk/src/winmm/initterm.cpp@ 51

Last change on this file since 51 was 51, checked in by sandervl, 26 years ago

* empty log message *

File size: 5.2 KB
Line 
1/*
2 * WINMM DLL entry point
3 *
4 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
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 <os2.h>
28#include <stdlib.h>
29#include <stdio.h>
30#include <string.h>
31#include <builtin.h>
32#include <misc.h> /*PLF Wed 98-03-18 23:19:26*/
33#include <odin.h>
34#include "aux.h"
35
36
37extern "C" {
38void IRTMidiShutdown(); // IRTMidi shutdown routine
39
40/*-------------------------------------------------------------------*/
41/* _CRT_init is the C run-time environment initialization function. */
42/* It will return 0 to indicate success and -1 to indicate failure. */
43/*-------------------------------------------------------------------*/
44int CDECL CRT_init(void);
45/*-------------------------------------------------------------------*/
46/* _CRT_term is the C run-time environment termination function. */
47/* It only needs to be called when the C run-time functions are */
48/* statically linked. */
49/*-------------------------------------------------------------------*/
50void CDECL CRT_term(void);
51void CDECL _ctordtorInit( void );
52void CDECL _ctordtorTerm( void );
53}
54
55/*-------------------------------------------------------------------*/
56/* A clean up routine registered with DosExitList must be used if */
57/* runtime calls are required and the runtime is dynamically linked. */
58/* This will guarantee that this clean up routine is run before the */
59/* library DLL is terminated. */
60/*-------------------------------------------------------------------*/
61static void APIENTRY cleanup(ULONG reason);
62
63
64
65/****************************************************************************/
66/* _DLL_InitTerm is the function that gets called by the operating system */
67/* loader when it loads and frees this DLL for each process that accesses */
68/* this DLL. However, it only gets called the first time the DLL is loaded */
69/* and the last time it is freed for a particular process. The system */
70/* linkage convention MUST be used because the operating system loader is */
71/* calling this function. */
72/****************************************************************************/
73unsigned long _System _DLL_InitTerm(unsigned long hModule, unsigned long
74 ulFlag)
75{
76 size_t i;
77 APIRET rc;
78
79 /*-------------------------------------------------------------------------*/
80 /* If ulFlag is zero then the DLL is being loaded so initialization should */
81 /* be performed. If ulFlag is 1 then the DLL is being freed so */
82 /* termination should be performed. */
83 /*-------------------------------------------------------------------------*/
84
85 switch (ulFlag) {
86 case 0 :
87
88 /*******************************************************************/
89 /* The C run-time environment initialization function must be */
90 /* called before any calls to C run-time functions that are not */
91 /* inlined. */
92 /*******************************************************************/
93
94 if (CRT_init() == -1)
95 return 0UL;
96 _ctordtorInit();
97
98 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
99
100 /*******************************************************************/
101 /* A DosExitList routine must be used to clean up if runtime calls */
102 /* are required and the runtime is dynamically linked. */
103 /*******************************************************************/
104
105 rc = DosExitList(0x0000FF00|EXLST_ADD, cleanup);
106 if(rc)
107 return 0UL;
108
109 break;
110 case 1 :
111 auxOS2Close(); /* SvL: Close aux device if necessary */
112 break;
113 default :
114 return 0UL;
115 }
116
117 /***********************************************************/
118 /* A non-zero value must be returned to indicate success. */
119 /***********************************************************/
120 return 1UL;
121}
122
123
124static void APIENTRY cleanup(ULONG ulReason)
125{
126 auxOS2Close(); /* SvL: Close aux device if necessary */
127 IRTMidiShutdown; /* JT: Shutdown RT Midi subsystem, if running. */
128 _ctordtorTerm();
129 CRT_term();
130 DosExitList(EXLST_EXIT, cleanup);
131 return ;
132}
133
Note: See TracBrowser for help on using the repository browser.