source: trunk/src/oleaut32/initterm.cpp@ 6648

Last change on this file since 6648 was 6648, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 4.3 KB
Line 
1/* $Id: initterm.cpp,v 1.10 2001-09-05 13:19:00 bird Exp $ */
2/*
3 * DLL entry point
4 *
5 * Copyright 1998 Sander van Leeuwen
6 * Copyright 1998 Peter Fitzsimmons
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13/*-------------------------------------------------------------*/
14/* INITERM.C -- Source for a custom dynamic link library */
15/* initialization and termination (_DLL_InitTerm) */
16/* function. */
17/* */
18/* When called to perform initialization, this sample function */
19/* gets storage for an array of integers, and initializes its */
20/* elements with random integers. At termination time, it */
21/* frees the array. Substitute your own special processing. */
22/*-------------------------------------------------------------*/
23
24
25/* Include files */
26#define INCL_DOSMODULEMGR
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
39extern "C" {
40 //Win32 resource table (produced by wrc)
41 extern DWORD _Resource_PEResTab;
42}
43static HMODULE dllHandle = 0;
44
45//Global DLL Data
46#pragma data_seg(_GLOBALDATA)
47int globLoadNr = 0;
48#pragma data_seg()
49
50char oleaut32Path[CCHMAXPATH] = "";
51int loadNr = 0;
52
53void Hash_Initialise(void);
54
55//******************************************************************************
56//******************************************************************************
57BOOL WINAPI LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
58{
59 switch (fdwReason)
60 {
61 case DLL_PROCESS_ATTACH:
62 return TRUE;
63
64 case DLL_THREAD_ATTACH:
65 case DLL_THREAD_DETACH:
66 return TRUE;
67
68 case DLL_PROCESS_DETACH:
69 ctordtorTerm();
70 ClosePrivateLogFiles();
71 return TRUE;
72 }
73 return FALSE;
74}
75/****************************************************************************/
76/* _DLL_InitTerm is the function that gets called by the operating system */
77/* loader when it loads and frees this DLL for each process that accesses */
78/* this DLL. However, it only gets called the first time the DLL is loaded */
79/* and the last time it is freed for a particular process. The system */
80/* linkage convention MUST be used because the operating system loader is */
81/* calling this function. */
82/****************************************************************************/
83unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
84 ulFlag)
85{
86 size_t i;
87 APIRET rc;
88
89 /*-------------------------------------------------------------------------*/
90 /* If ulFlag is zero then the DLL is being loaded so initialization should */
91 /* be performed. If ulFlag is 1 then the DLL is being freed so */
92 /* termination should be performed. */
93 /*-------------------------------------------------------------------------*/
94
95 switch (ulFlag) {
96 case 0 :
97 {
98 loadNr = globLoadNr++;
99
100 DosQueryModuleName(hModule, sizeof(oleaut32Path), oleaut32Path);
101 char *endofpath = strrchr(oleaut32Path, '\\');
102 *(endofpath+1) = 0;
103
104 ctordtorInit();
105
106 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
107
108 dllHandle = RegisterLxDll(hModule, LibMain, (PVOID)&_Resource_PEResTab);
109 if(dllHandle == 0)
110 return 0UL;
111
112#ifdef DEFAULT_LOGGING_OFF
113 if(getenv("WIN32LOG_ENABLED")) {
114#else
115 if(!getenv("NOWIN32LOG")) {
116#endif
117 OpenPrivateLogFiles();
118 }
119 Hash_Initialise();
120
121 break;
122 }
123 case 1 :
124 if(dllHandle) {
125 UnregisterLxDll(dllHandle);
126 }
127 break;
128
129 default :
130 return 0UL;
131 }
132
133 /***********************************************************/
134 /* A non-zero value must be returned to indicate success. */
135 /***********************************************************/
136 return 1UL;
137}
138//******************************************************************************
139//******************************************************************************
Note: See TracBrowser for help on using the repository browser.