source: trunk/src/wnaspi32/initwnaspi32.cpp@ 7143

Last change on this file since 7143 was 7143, checked in by achimha, 24 years ago

fail gracefully if no ASPI there

File size: 4.3 KB
Line 
1/* $Id: initwnaspi32.cpp,v 1.2 2001-10-20 09:49:01 achimha 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#include "aspilib.h"
39
40extern "C" {
41 //Win32 resource table (produced by wrc)
42 extern DWORD wnaspi32_PEResTab;
43}
44scsiObj *aspi = NULL;
45static HMODULE dllHandle = 0;
46//******************************************************************************
47//******************************************************************************
48BOOL WINAPI Wnaspi32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
49{
50 switch (fdwReason)
51 {
52 case DLL_PROCESS_ATTACH:
53 aspi = new scsiObj();
54 if(aspi == NULL) {
55 dprintf(("WNASPI32: LibMain; can't allocate aspi object! APIs will not work!"));
56 // @@@AH 20011020 we shouldn't prevent DLL loading in this case
57 // just make sure that all API calls fail
58 return TRUE;
59 }
60 if(aspi->init(65535) == FALSE)
61 {
62 delete aspi;
63 aspi = NULL;
64 dprintf(("WNASPI32: LibMain; can't init aspi object!"));
65 return FALSE;
66 }
67 dprintf(("WNASPI32: LibMain; aspi object created successfully"));
68 return TRUE;
69
70 case DLL_THREAD_ATTACH:
71 case DLL_THREAD_DETACH:
72 return TRUE;
73
74 case DLL_PROCESS_DETACH:
75 if(aspi) {
76 aspi->close();
77 delete aspi;
78 aspi = NULL;
79 }
80 return TRUE;
81 }
82 return FALSE;
83}
84/****************************************************************************/
85/* _DLL_InitTerm is the function that gets called by the operating system */
86/* loader when it loads and frees this DLL for each process that accesses */
87/* this DLL. However, it only gets called the first time the DLL is loaded */
88/* and the last time it is freed for a particular process. The system */
89/* linkage convention MUST be used because the operating system loader is */
90/* calling this function. */
91/****************************************************************************/
92ULONG APIENTRY inittermWnaspi32(ULONG hModule, ULONG ulFlag)
93{
94 size_t i;
95 APIRET rc;
96
97 /*-------------------------------------------------------------------------*/
98 /* If ulFlag is zero then the DLL is being loaded so initialization should */
99 /* be performed. If ulFlag is 1 then the DLL is being freed so */
100 /* termination should be performed. */
101 /*-------------------------------------------------------------------------*/
102
103 switch (ulFlag) {
104 case 0 :
105 dllHandle = RegisterLxDll(hModule, Wnaspi32LibMain, (PVOID)&wnaspi32_PEResTab);
106 if(dllHandle == 0)
107 return 0UL;
108
109 break;
110 case 1 :
111 if(dllHandle) {
112 UnregisterLxDll(dllHandle);
113 }
114 break;
115 default :
116 return 0UL;
117 }
118
119 /***********************************************************/
120 /* A non-zero value must be returned to indicate success. */
121 /***********************************************************/
122 return 1UL;
123}
124//******************************************************************************
125//******************************************************************************
Note: See TracBrowser for help on using the repository browser.