[8601] | 1 | /* $Id: initwnaspi32.cpp,v 1.1 2002-06-08 11:42:03 sandervl 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 <win32api.h>
|
---|
| 35 | #include <winconst.h>
|
---|
| 36 | #include <odinlx.h>
|
---|
| 37 | #include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
|
---|
| 38 | #include <initdll.h>
|
---|
| 39 | #include "aspilib.h"
|
---|
| 40 | #include <custombuild.h>
|
---|
| 41 |
|
---|
| 42 | extern "C" {
|
---|
| 43 | //Win32 resource table (produced by wrc)
|
---|
| 44 | extern DWORD wnaspi32_PEResTab;
|
---|
| 45 | }
|
---|
| 46 | scsiObj *aspi = NULL;
|
---|
| 47 | static HMODULE dllHandle = 0;
|
---|
| 48 | static BOOL fDisableASPI = FALSE;
|
---|
| 49 |
|
---|
| 50 | //******************************************************************************
|
---|
| 51 | //******************************************************************************
|
---|
| 52 | void WIN32API DisableASPI()
|
---|
| 53 | {
|
---|
| 54 | dprintf(("DisableASPI"));
|
---|
| 55 | fDisableASPI = TRUE;
|
---|
| 56 | }
|
---|
| 57 | //******************************************************************************
|
---|
| 58 | //******************************************************************************
|
---|
| 59 | BOOL WINAPI Wnaspi32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
---|
| 60 | {
|
---|
| 61 | switch (fdwReason)
|
---|
| 62 | {
|
---|
| 63 | case DLL_PROCESS_ATTACH:
|
---|
| 64 | {
|
---|
| 65 | if(fDisableASPI) return TRUE;
|
---|
| 66 |
|
---|
| 67 | aspi = new scsiObj();
|
---|
| 68 | if(aspi == NULL) {
|
---|
| 69 | dprintf(("WNASPI32: LibMain; can't allocate aspi object! APIs will not work!"));
|
---|
| 70 | // @@@AH 20011020 we shouldn't prevent DLL loading in this case
|
---|
| 71 | // just make sure that all API calls fail
|
---|
| 72 | return TRUE;
|
---|
| 73 | }
|
---|
| 74 | if(aspi->init(65535) == FALSE)
|
---|
| 75 | {
|
---|
| 76 | delete aspi;
|
---|
| 77 | aspi = NULL;
|
---|
| 78 | dprintf(("WNASPI32: LibMain; can't init aspi object!"));
|
---|
| 79 | // @@@20011026 and also in this case we shouldn't prevent DLL loading...
|
---|
| 80 | return TRUE;
|
---|
| 81 | }
|
---|
| 82 | dprintf(("WNASPI32: LibMain; aspi object created successfully"));
|
---|
| 83 | return TRUE;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | case DLL_THREAD_ATTACH:
|
---|
| 87 | case DLL_THREAD_DETACH:
|
---|
| 88 | return TRUE;
|
---|
| 89 |
|
---|
| 90 | case DLL_PROCESS_DETACH:
|
---|
| 91 | if(aspi) {
|
---|
| 92 | aspi->close();
|
---|
| 93 | delete aspi;
|
---|
| 94 | aspi = NULL;
|
---|
| 95 | }
|
---|
| 96 | return TRUE;
|
---|
| 97 | }
|
---|
| 98 | return FALSE;
|
---|
| 99 | }
|
---|
| 100 | /****************************************************************************/
|
---|
| 101 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
---|
| 102 | /* loader when it loads and frees this DLL for each process that accesses */
|
---|
| 103 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
---|
| 104 | /* and the last time it is freed for a particular process. The system */
|
---|
| 105 | /* linkage convention MUST be used because the operating system loader is */
|
---|
| 106 | /* calling this function. */
|
---|
| 107 | /****************************************************************************/
|
---|
| 108 | ULONG APIENTRY inittermWnaspi32(ULONG hModule, ULONG ulFlag)
|
---|
| 109 | {
|
---|
| 110 | size_t i;
|
---|
| 111 | APIRET rc;
|
---|
| 112 |
|
---|
| 113 | /*-------------------------------------------------------------------------*/
|
---|
| 114 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
---|
| 115 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
---|
| 116 | /* termination should be performed. */
|
---|
| 117 | /*-------------------------------------------------------------------------*/
|
---|
| 118 |
|
---|
| 119 | switch (ulFlag) {
|
---|
| 120 | case 0 :
|
---|
| 121 | dllHandle = RegisterLxDll(hModule, Wnaspi32LibMain, (PVOID)&wnaspi32_PEResTab);
|
---|
| 122 | if(dllHandle == 0)
|
---|
| 123 | return 0UL;
|
---|
| 124 |
|
---|
| 125 | break;
|
---|
| 126 | case 1 :
|
---|
| 127 | if(dllHandle) {
|
---|
| 128 | UnregisterLxDll(dllHandle);
|
---|
| 129 | }
|
---|
| 130 | break;
|
---|
| 131 | default :
|
---|
| 132 | return 0UL;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | /***********************************************************/
|
---|
| 136 | /* A non-zero value must be returned to indicate success. */
|
---|
| 137 | /***********************************************************/
|
---|
| 138 | return 1UL;
|
---|
| 139 | }
|
---|
| 140 | //******************************************************************************
|
---|
| 141 | //******************************************************************************
|
---|