source: trunk/src/ddraw/initterm.cpp@ 6496

Last change on this file since 6496 was 5326, checked in by mike, 24 years ago

Merged DDRAW and DDRAW\NEW

File size: 4.6 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 <win32type.h>
33#include <winconst.h>
34#include <odinlx.h>
35#include <exitlist.h>
36#include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
37#include <initdll.h>
38#include "os2fsdd.h" // For RestorePM()
39
40
41extern "C" {
42 //Win32 resource table (produced by wrc)
43 extern DWORD _Resource_PEResTab;
44}
45
46char ddrawPath[CCHMAXPATH] = "";
47static HMODULE dllHandle = 0;
48
49static void APIENTRY cleanup(ULONG ulReason);
50
51//******************************************************************************
52//******************************************************************************
53BOOL WINAPI LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
54{
55 switch (fdwReason)
56 {
57 case DLL_PROCESS_ATTACH:
58 return TRUE;
59
60 case DLL_THREAD_ATTACH:
61 case DLL_THREAD_DETACH:
62 return TRUE;
63
64 case DLL_PROCESS_DETACH:
65#ifdef __IBMCPP__
66 ctordtorTerm();
67#endif
68 return TRUE;
69 }
70 return FALSE;
71}
72/****************************************************************************/
73/* _DLL_InitTerm is the function that gets called by the operating system */
74/* loader when it loads and frees this DLL for each process that accesses */
75/* this DLL. However, it only gets called the first time the DLL is loaded */
76/* and the last time it is freed for a particular process. The system */
77/* linkage convention MUST be used because the operating system loader is */
78/* calling this function. */
79/****************************************************************************/
80unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
81 ulFlag)
82{
83
84 /*-------------------------------------------------------------------------*/
85 /* If ulFlag is zero then the DLL is being loaded so initialization should */
86 /* be performed. If ulFlag is 1 then the DLL is being freed so */
87 /* termination should be performed. */
88 /*-------------------------------------------------------------------------*/
89
90 switch (ulFlag) {
91 case 0 :
92 {
93 APIRET rc;
94
95#ifdef __IBMCPP__
96 ctordtorInit();
97#endif
98 DosQueryModuleName(hModule, CCHMAXPATH, ddrawPath);
99 char *endofpath = strrchr(ddrawPath, '\\');
100 if (endofpath)
101 *(endofpath+1) = '\0';
102
103 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
104
105 dllHandle = RegisterLxDll(hModule, LibMain, (PVOID)&_Resource_PEResTab,
106 DDRAW_MAJORIMAGE_VERSION, DDRAW_MINORIMAGE_VERSION,
107 IMAGE_SUBSYSTEM_WINDOWS_GUI);
108 if (dllHandle == 0)
109 return 0UL;
110
111 rc = DosExitList(EXITLIST_NONCOREDLL | EXLST_ADD, cleanup);
112 if (rc)
113 return 0UL;
114
115 break;
116 }
117 case 1 :
118 if(dllHandle) {
119 UnregisterLxDll(dllHandle);
120 }
121 break;
122 default :
123 return 0UL;
124 }
125
126 /***********************************************************/
127 /* A non-zero value must be returned to indicate success. */
128 /***********************************************************/
129 return 1UL;
130}
131//******************************************************************************
132//******************************************************************************
133
134static void APIENTRY cleanup(ULONG ulReason)
135{
136 dprintf(("DDRAW processing exitlist"));
137 RestorePM();
138 dprintf(("DDRAW exitlist done"));
139
140 DosExitList(EXLST_EXIT, cleanup);
141}
142//******************************************************************************
143//******************************************************************************
Note: See TracBrowser for help on using the repository browser.