| 1 | /* $Id: initterm.cpp,v 1.7 2000-01-15 22:02:07 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 | ULONG twaintype;
|
|---|
| 79 |
|
|---|
| 80 | /*-------------------------------------------------------------------------*/
|
|---|
| 81 | /* If ulFlag is zero then the DLL is being loaded so initialization should */
|
|---|
| 82 | /* be performed. If ulFlag is 1 then the DLL is being freed so */
|
|---|
| 83 | /* termination should be performed. */
|
|---|
| 84 | /*-------------------------------------------------------------------------*/
|
|---|
| 85 |
|
|---|
| 86 | switch (ulFlag) {
|
|---|
| 87 | case 0 :
|
|---|
| 88 | _ctordtorInit();
|
|---|
| 89 |
|
|---|
| 90 | CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
|
|---|
| 91 |
|
|---|
| 92 | twaintype = PROFILE_GetOdinIniInt("TWAIN","TwainIF",1);
|
|---|
| 93 | switch(twaintype)
|
|---|
| 94 | {
|
|---|
| 95 | case 1:
|
|---|
| 96 | default:
|
|---|
| 97 | {
|
|---|
| 98 | dprintf(("TWAIN_32: Using CFM-Twain as Twain Source.\n\n"));
|
|---|
| 99 | hTWAIN = LoadLibraryA("TWAINOS2.DLL");
|
|---|
| 100 | if(hTWAIN)
|
|---|
| 101 | {
|
|---|
| 102 | *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry");
|
|---|
| 103 | }
|
|---|
| 104 | else
|
|---|
| 105 | {
|
|---|
| 106 | return 0UL;
|
|---|
| 107 | }
|
|---|
| 108 | break;
|
|---|
| 109 | }
|
|---|
| 110 | case 2:
|
|---|
| 111 | {
|
|---|
| 112 | dprintf(("TWAIN_32: Using STI-Twain as Twain Source.\n\n"));
|
|---|
| 113 | hTWAIN = LoadLibraryA("TWAIN.DLL");
|
|---|
| 114 | if(hTWAIN)
|
|---|
| 115 | {
|
|---|
| 116 | *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_ENTRY");
|
|---|
| 117 | }
|
|---|
| 118 | else
|
|---|
| 119 | {
|
|---|
| 120 | return 0UL;
|
|---|
| 121 | }
|
|---|
| 122 | break;
|
|---|
| 123 | }
|
|---|
| 124 | case 3:
|
|---|
| 125 | {
|
|---|
| 126 | dprintf(("TWAIN_32: Using SANE as Twain Source (currently not supported).\n\n"));
|
|---|
| 127 | // hTWAIN = LoadLibraryA("TWAINSNE.DLL");
|
|---|
| 128 | // if(hTWAIN)
|
|---|
| 129 | // {
|
|---|
| 130 | // *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry");
|
|---|
| 131 | // }
|
|---|
| 132 | return 0UL;
|
|---|
| 133 | }
|
|---|
| 134 | }
|
|---|
| 135 | /*******************************************************************/
|
|---|
| 136 | /* A DosExitList routine must be used to clean up if runtime calls */
|
|---|
| 137 | /* are required and the runtime is dynamically linked. */
|
|---|
| 138 | /*******************************************************************/
|
|---|
| 139 |
|
|---|
| 140 | if(RegisterLxDll(hModule, 0, (PVOID)&_Resource_PEResTab) == FALSE)
|
|---|
| 141 | return 0UL;
|
|---|
| 142 |
|
|---|
| 143 | rc = DosExitList(0x0000F000|EXLST_ADD, cleanup);
|
|---|
| 144 | if(rc)
|
|---|
| 145 | return 0UL;
|
|---|
| 146 |
|
|---|
| 147 | break;
|
|---|
| 148 | case 1 :
|
|---|
| 149 | if(hTWAIN)
|
|---|
| 150 | FreeLibrary(hTWAIN);
|
|---|
| 151 | hTWAIN = 0;
|
|---|
| 152 | UnregisterLxDll(hModule);
|
|---|
| 153 | break;
|
|---|
| 154 | default :
|
|---|
| 155 | return 0UL;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /***********************************************************/
|
|---|
| 159 | /* A non-zero value must be returned to indicate success. */
|
|---|
| 160 | /***********************************************************/
|
|---|
| 161 | return 1UL;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | static void APIENTRY cleanup(ULONG ulReason)
|
|---|
| 166 | {
|
|---|
| 167 | _ctordtorTerm();
|
|---|
| 168 | DosExitList(EXLST_EXIT, cleanup);
|
|---|
| 169 | return ;
|
|---|
| 170 | }
|
|---|