| 1 | /* $Id: initterm.cpp,v 1.4 2000-01-05 23:28:26 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * DLL entry point
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen
|
|---|
| 7 | * Copyright 1998 Peter Fitzsimmons
|
|---|
| 8 | *
|
|---|
| 9 | *
|
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 11 | *
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | /*-------------------------------------------------------------*/
|
|---|
| 15 | /* INITERM.C -- Source for a custom dynamic link library */
|
|---|
| 16 | /* initialization and termination (_DLL_InitTerm) */
|
|---|
| 17 | /* function. */
|
|---|
| 18 | /* */
|
|---|
| 19 | /* When called to perform initialization, this sample function */
|
|---|
| 20 | /* gets storage for an array of integers, and initializes its */
|
|---|
| 21 | /* elements with random integers. At termination time, it */
|
|---|
| 22 | /* frees the array. Substitute your own special processing. */
|
|---|
| 23 | /*-------------------------------------------------------------*/
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | /* Include files */
|
|---|
| 27 | #define INCL_DOSMODULEMGR
|
|---|
| 28 | #define INCL_DOSPROCESS
|
|---|
| 29 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 30 | #include <stdlib.h>
|
|---|
| 31 | #include <stdio.h>
|
|---|
| 32 | #include <string.h>
|
|---|
| 33 | #include <odin.h>
|
|---|
| 34 | #include <win32type.h>
|
|---|
| 35 | #include <odinlx.h>
|
|---|
| 36 | #include <misc.h> /*PLF Wed 98-03-18 23:18:15*/
|
|---|
| 37 | #include <twain.h>
|
|---|
| 38 |
|
|---|
| 39 | extern "C" {
|
|---|
| 40 | void CDECL _ctordtorInit( void );
|
|---|
| 41 | void CDECL _ctordtorTerm( void );
|
|---|
| 42 |
|
|---|
| 43 | //Win32 resource table (produced by wrc)
|
|---|
| 44 | extern DWORD _Resource_PEResTab;
|
|---|
| 45 |
|
|---|
| 46 | extern FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
|
|---|
| 47 | extern HMODULE WINAPI LoadLibraryA(LPCSTR);
|
|---|
| 48 | extern BOOL WINAPI FreeLibrary(HMODULE);
|
|---|
| 49 | extern int WINAPI PROFILE_GetOdinIniInt(LPCSTR section,LPCSTR key_name,int def);
|
|---|
| 50 | TW_UINT16 (APIENTRY *TWAINOS2_DSM_Entry)( pTW_IDENTITY, pTW_IDENTITY,
|
|---|
| 51 | TW_UINT32, TW_UINT16, TW_UINT16, TW_MEMREF) = 0;
|
|---|
| 52 | static HINSTANCE hTWAIN = 0;
|
|---|
| 53 |
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | /*-------------------------------------------------------------------*/
|
|---|
| 57 | /* A clean up routine registered with DosExitList must be used if */
|
|---|
| 58 | /* runtime calls are required and the runtime is dynamically linked. */
|
|---|
| 59 | /* This will guarantee that this clean up routine is run before the */
|
|---|
| 60 | /* library DLL is terminated. */
|
|---|
| 61 | /*-------------------------------------------------------------------*/
|
|---|
| 62 | static void APIENTRY cleanup(ULONG reason);
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | /****************************************************************************/
|
|---|
| 66 | /* _DLL_InitTerm is the function that gets called by the operating system */
|
|---|
| 67 | /* loader when it loads and frees this DLL for each process that accesses */
|
|---|
| 68 | /* this DLL. However, it only gets called the first time the DLL is loaded */
|
|---|
| 69 | /* and the last time it is freed for a particular process. The system */
|
|---|
| 70 | /* linkage convention MUST be used because the operating system loader is */
|
|---|
| 71 | /* calling this function. */
|
|---|
| 72 | /****************************************************************************/
|
|---|
| 73 | unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
|
|---|
| 74 | ulFlag)
|
|---|
| 75 | {
|
|---|
| 76 | size_t i;
|
|---|
| 77 | APIRET rc;
|
|---|
| 78 |
|
|---|
| 79 | /*-------------------------------------------------------------------------*/
|
|---|
| 80 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
|---|
| 81 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
|---|
| 82 | /* termination should be performed. */
|
|---|
| 83 | /*-------------------------------------------------------------------------*/
|
|---|
| 84 |
|
|---|
| 85 | switch (ulFlag) {
|
|---|
| 86 | case 0 :
|
|---|
| 87 | _ctordtorInit();
|
|---|
| 88 |
|
|---|
| 89 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
|---|
| 90 |
|
|---|
| 91 | if (PROFILE_GetOdinIniInt("TWAIN","TwainIF",1) == 1)
|
|---|
| 92 | {
|
|---|
| 93 | dprintf(("TWAIN_32: Using CFM-Twain as Twain Source.\n\n"));
|
|---|
| 94 | hTWAIN = LoadLibraryA("TWAINOS2.DLL");
|
|---|
| 95 | if(hTWAIN)
|
|---|
| 96 | {
|
|---|
| 97 | *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry");
|
|---|
| 98 | }
|
|---|
| 99 | else
|
|---|
| 100 | {
|
|---|
| 101 | return 0UL;
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | if (PROFILE_GetOdinIniInt("TWAIN","TwainIF",0) == 2)
|
|---|
| 106 | {
|
|---|
| 107 | dprintf(("TWAIN_32: Using STI-Twain as Twain Source (currently not supported).\n\n"));
|
|---|
| 108 | // hTWAIN = LoadLibraryA("TWAIN.DLL");
|
|---|
| 109 | // if(hTWAIN)
|
|---|
| 110 | // {
|
|---|
| 111 | // *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry");
|
|---|
| 112 | // }
|
|---|
| 113 | return 0UL;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | if (PROFILE_GetOdinIniInt("TWAIN","TwainIF",0) == 3)
|
|---|
| 117 | {
|
|---|
| 118 | dprintf(("TWAIN_32: Using SANE as Twain Source (currently not supported).\n\n"));
|
|---|
| 119 | // hTWAIN = LoadLibraryA("TWAINSNE.DLL");
|
|---|
| 120 | // if(hTWAIN)
|
|---|
| 121 | // {
|
|---|
| 122 | // *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry");
|
|---|
| 123 | // }
|
|---|
| 124 | return 0UL;
|
|---|
| 125 | }
|
|---|
| 126 | if (PROFILE_GetOdinIniInt("TWAIN","TwainIF",0) != 1 &&
|
|---|
| 127 | PROFILE_GetOdinIniInt("TWAIN","TwainIF",0) != 2 &&
|
|---|
| 128 | PROFILE_GetOdinIniInt("TWAIN","TwainIF",0) != 3)
|
|---|
| 129 | {
|
|---|
| 130 | dprintf(("TWAIN_32: No or wrong TwainIF specified, using CFM-Twain as Twain Source.\n\n"));
|
|---|
| 131 | hTWAIN = LoadLibraryA("TWAINOS2.DLL");
|
|---|
| 132 | if(hTWAIN)
|
|---|
| 133 | {
|
|---|
| 134 | *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry");
|
|---|
| 135 | }
|
|---|
| 136 | else
|
|---|
| 137 | {
|
|---|
| 138 | return 0UL;
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /*******************************************************************/
|
|---|
| 143 | /* A DosExitList routine must be used to clean up if runtime calls */
|
|---|
| 144 | /* are required and the runtime is dynamically linked. */
|
|---|
| 145 | /*******************************************************************/
|
|---|
| 146 |
|
|---|
| 147 | if(RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab) == FALSE)
|
|---|
| 148 | return 0UL;
|
|---|
| 149 |
|
|---|
| 150 | rc = DosExitList(0x0000F000|EXLST_ADD, cleanup);
|
|---|
| 151 | if(rc)
|
|---|
| 152 | return 0UL;
|
|---|
| 153 |
|
|---|
| 154 | break;
|
|---|
| 155 | case 1 :
|
|---|
| 156 | if(hTWAIN)
|
|---|
| 157 | FreeLibrary(hTWAIN);
|
|---|
| 158 | hTWAIN = 0;
|
|---|
| 159 | UnregisterLxDll(hModule);
|
|---|
| 160 | break;
|
|---|
| 161 | default :
|
|---|
| 162 | return 0UL;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | /***********************************************************/
|
|---|
| 166 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 167 | /***********************************************************/
|
|---|
| 168 | return 1UL;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | static void APIENTRY cleanup(ULONG ulReason)
|
|---|
| 173 | {
|
|---|
| 174 | _ctordtorTerm();
|
|---|
| 175 | DosExitList(EXLST_EXIT, cleanup);
|
|---|
| 176 | return ;
|
|---|
| 177 | }
|
|---|