| 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 <misc.h>       /*PLF Wed  98-03-18 23:18:15*/ | 
|---|
| 36 | #include <twain.h> | 
|---|
| 37 | #include <initdll.h> | 
|---|
| 38 |  | 
|---|
| 39 | extern "C" { | 
|---|
| 40 | //Win32 resource table (produced by wrc) | 
|---|
| 41 | extern DWORD _Resource_PEResTab; | 
|---|
| 42 |  | 
|---|
| 43 | extern FARPROC   WINAPI GetProcAddress(HMODULE,LPCSTR); | 
|---|
| 44 | extern HMODULE   WINAPI LoadLibraryA(LPCSTR); | 
|---|
| 45 | extern BOOL      WINAPI FreeLibrary(HMODULE); | 
|---|
| 46 | extern int WINAPI PROFILE_GetOdinIniInt(LPCSTR section,LPCSTR key_name,int def); | 
|---|
| 47 | TW_UINT16 (APIENTRY *TWAINOS2_DSM_Entry)( pTW_IDENTITY, pTW_IDENTITY, | 
|---|
| 48 | TW_UINT32, TW_UINT16, TW_UINT16, TW_MEMREF) = 0; | 
|---|
| 49 | static HINSTANCE hTWAIN = 0; | 
|---|
| 50 |  | 
|---|
| 51 | } | 
|---|
| 52 | static HMODULE dllHandle = 0; | 
|---|
| 53 |  | 
|---|
| 54 | //****************************************************************************** | 
|---|
| 55 | //****************************************************************************** | 
|---|
| 56 | BOOL WINAPI LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad) | 
|---|
| 57 | { | 
|---|
| 58 | switch (fdwReason) | 
|---|
| 59 | { | 
|---|
| 60 | case DLL_PROCESS_ATTACH: | 
|---|
| 61 | return TRUE; | 
|---|
| 62 |  | 
|---|
| 63 | case DLL_THREAD_ATTACH: | 
|---|
| 64 | case DLL_THREAD_DETACH: | 
|---|
| 65 | return TRUE; | 
|---|
| 66 |  | 
|---|
| 67 | case DLL_PROCESS_DETACH: | 
|---|
| 68 | ctordtorTerm(); | 
|---|
| 69 | return TRUE; | 
|---|
| 70 | } | 
|---|
| 71 | return FALSE; | 
|---|
| 72 | } | 
|---|
| 73 | /****************************************************************************/ | 
|---|
| 74 | /* _DLL_InitTerm is the function that gets called by the operating system   */ | 
|---|
| 75 | /* loader when it loads and frees this DLL for each process that accesses   */ | 
|---|
| 76 | /* this DLL.  However, it only gets called the first time the DLL is loaded */ | 
|---|
| 77 | /* and the last time it is freed for a particular process.  The system      */ | 
|---|
| 78 | /* linkage convention MUST be used because the operating system loader is   */ | 
|---|
| 79 | /* calling this function.                                                   */ | 
|---|
| 80 | /****************************************************************************/ | 
|---|
| 81 | unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long | 
|---|
| 82 | ulFlag) | 
|---|
| 83 | { | 
|---|
| 84 | size_t i; | 
|---|
| 85 | APIRET rc; | 
|---|
| 86 | ULONG  twaintype; | 
|---|
| 87 |  | 
|---|
| 88 | /*-------------------------------------------------------------------------*/ | 
|---|
| 89 | /* If ulFlag is zero then the DLL is being loaded so initialization should */ | 
|---|
| 90 | /* be performed.  If ulFlag is 1 then the DLL is being freed so            */ | 
|---|
| 91 | /* termination should be performed.                                        */ | 
|---|
| 92 | /*-------------------------------------------------------------------------*/ | 
|---|
| 93 |  | 
|---|
| 94 | switch (ulFlag) { | 
|---|
| 95 | case 0 : | 
|---|
| 96 | ctordtorInit(); | 
|---|
| 97 |  | 
|---|
| 98 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/ | 
|---|
| 99 |  | 
|---|
| 100 | twaintype = PROFILE_GetOdinIniInt("TWAIN","TwainIF",1); | 
|---|
| 101 | switch(twaintype) | 
|---|
| 102 | { | 
|---|
| 103 | case 1: | 
|---|
| 104 | default: | 
|---|
| 105 | { | 
|---|
| 106 | dprintf(("TWAIN_32: Using CFM-Twain as Twain Source.\n\n")); | 
|---|
| 107 | hTWAIN = LoadLibraryA("TWAINOS2.DLL"); | 
|---|
| 108 | if(hTWAIN) | 
|---|
| 109 | { | 
|---|
| 110 | *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry"); | 
|---|
| 111 | } | 
|---|
| 112 | else | 
|---|
| 113 | { | 
|---|
| 114 | return 0UL; | 
|---|
| 115 | } | 
|---|
| 116 | break; | 
|---|
| 117 | } | 
|---|
| 118 | case 2: | 
|---|
| 119 | { | 
|---|
| 120 | dprintf(("TWAIN_32: Using STI-Twain as Twain Source.\n\n")); | 
|---|
| 121 | hTWAIN = LoadLibraryA("TWAIN.DLL"); | 
|---|
| 122 | if(hTWAIN) | 
|---|
| 123 | { | 
|---|
| 124 | *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_ENTRY"); | 
|---|
| 125 | } | 
|---|
| 126 | else | 
|---|
| 127 | { | 
|---|
| 128 | return 0UL; | 
|---|
| 129 | } | 
|---|
| 130 | break; | 
|---|
| 131 | } | 
|---|
| 132 | case 3: | 
|---|
| 133 | { | 
|---|
| 134 | dprintf(("TWAIN_32: Using SANE as Twain Source  (currently not supported).\n\n")); | 
|---|
| 135 | //            hTWAIN = LoadLibraryA("TWAINSNE.DLL"); | 
|---|
| 136 | //            if(hTWAIN) | 
|---|
| 137 | //            { | 
|---|
| 138 | //                *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry"); | 
|---|
| 139 | //            } | 
|---|
| 140 | return 0UL; | 
|---|
| 141 | } | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | dllHandle = RegisterLxDll(hModule, LibMain, (PVOID)&_Resource_PEResTab); | 
|---|
| 145 | if(dllHandle == 0) | 
|---|
| 146 | return 0UL; | 
|---|
| 147 |  | 
|---|
| 148 | break; | 
|---|
| 149 | case 1 : | 
|---|
| 150 | if(hTWAIN) | 
|---|
| 151 | FreeLibrary(hTWAIN); | 
|---|
| 152 | hTWAIN = 0; | 
|---|
| 153 | if(dllHandle) { | 
|---|
| 154 | UnregisterLxDll(dllHandle); | 
|---|
| 155 | } | 
|---|
| 156 | break; | 
|---|
| 157 | default  : | 
|---|
| 158 | return 0UL; | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | /***********************************************************/ | 
|---|
| 162 | /* A non-zero value must be returned to indicate success.  */ | 
|---|
| 163 | /***********************************************************/ | 
|---|
| 164 | return 1UL; | 
|---|
| 165 | } | 
|---|
| 166 | //****************************************************************************** | 
|---|
| 167 | //****************************************************************************** | 
|---|