source: trunk/src/twain_32/initterm.cpp@ 6071

Last change on this file since 6071 was 6071, checked in by hugh, 24 years ago

Updated InitTerm of Twain_32

File size: 6.2 KB
Line 
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
39extern "C" {
40//Win32 resource table (produced by wrc)
41extern DWORD _Resource_PEResTab;
42
43#if 0
44extern FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR);
45extern HMODULE WINAPI LoadLibraryA(LPCSTR);
46extern BOOL WINAPI FreeLibrary(HMODULE);
47#endif
48extern int WINAPI PROFILE_GetOdinIniInt(LPCSTR section,LPCSTR key_name,int def);
49TW_UINT16 (APIENTRY *TWAINOS2_DSM_Entry)( pTW_IDENTITY, pTW_IDENTITY,
50 TW_UINT32, TW_UINT16, TW_UINT16, TW_MEMREF) = 0;
51#if 0
52 static HINSTANCE hTWAIN = 0;
53#else
54 static HMODULE hTWAIN = 0;
55 char szLoadError[256];
56#endif
57}
58static HMODULE dllHandle = 0;
59
60//******************************************************************************
61//******************************************************************************
62BOOL WINAPI LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
63{
64 switch (fdwReason)
65 {
66 case DLL_PROCESS_ATTACH:
67 return TRUE;
68
69 case DLL_THREAD_ATTACH:
70 case DLL_THREAD_DETACH:
71 return TRUE;
72
73 case DLL_PROCESS_DETACH:
74 ctordtorTerm();
75 return TRUE;
76 }
77 return FALSE;
78}
79/****************************************************************************/
80/* _DLL_InitTerm is the function that gets called by the operating system */
81/* loader when it loads and frees this DLL for each process that accesses */
82/* this DLL. However, it only gets called the first time the DLL is loaded */
83/* and the last time it is freed for a particular process. The system */
84/* linkage convention MUST be used because the operating system loader is */
85/* calling this function. */
86/****************************************************************************/
87unsigned long SYSTEM _DLL_InitTerm(unsigned long hModule, unsigned long
88 ulFlag)
89{
90 size_t i;
91 APIRET rc;
92 ULONG twaintype;
93
94 /*-------------------------------------------------------------------------*/
95 /* If ulFlag is zero then the DLL is being loaded so initialization should */
96 /* be performed. If ulFlag is 1 then the DLL is being freed so */
97 /* termination should be performed. */
98 /*-------------------------------------------------------------------------*/
99
100 switch (ulFlag) {
101 case 0 :
102 ctordtorInit();
103
104 CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed 98-03-18 05:28:48*/
105
106 twaintype = PROFILE_GetOdinIniInt("TWAIN","TwainIF",1);
107 switch(twaintype)
108 {
109 case 1:
110 default:
111 {
112 dprintf(("TWAIN_32: Using CFM-Twain as Twain Source.\n\n"));
113#if 0
114 hTWAIN = LoadLibraryA("TWAINOS2.DLL");
115 if(hTWAIN)
116 {
117 *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_Entry");
118 }
119 else
120 {
121 return 0UL;
122 }
123#else
124 rc = DosLoadModule( szLoadError, sizeof(szLoadError), "TWAINOS2.DLL", &hTWAIN);
125 if(rc==0)
126 {
127 rc = DosQueryProcAddr(hTWAIN, 0, "DSM_Entry",(PFN*)&TWAINOS2_DSM_Entry);
128 }
129 else
130 {
131 dprintf(("TWAIN_32: Error Loading DLL: %s",szLoadError));
132 }
133 if(rc!=0)
134 {
135 return 0UL;
136 }
137#endif
138 break;
139 }
140 case 2:
141 {
142 dprintf(("TWAIN_32: Using STI-Twain as Twain Source.\n\n"));
143#if 0
144 hTWAIN = LoadLibraryA("TWAIN.DLL");
145 if(hTWAIN)
146 {
147 *(VOID **)&TWAINOS2_DSM_Entry=(void*)GetProcAddress(hTWAIN, (LPCSTR)"DSM_ENTRY");
148 }
149 else
150 {
151 return 0UL;
152 }
153#else
154 rc = DosLoadModule( szLoadError, sizeof(szLoadError), "TWAIN.DLL", &hTWAIN);
155 if(rc==0)
156 {
157 rc = DosQueryProcAddr(hTWAIN, 0, "DSM_Entry",(PFN*)&TWAINOS2_DSM_Entry);
158 }
159 else
160 {
161 dprintf(("TWAIN_32: Error Loading DLL: %s",szLoadError));
162 }
163 if(rc!=0)
164 {
165 return 0UL;
166 }
167#endif
168 break;
169 }
170 case 3:
171 {
172 dprintf(("TWAIN_32: Using SANE as Twain Source (currently not supported).\n\n"));
173 return 0UL;
174 }
175 }
176
177 dllHandle = RegisterLxDll(hModule, LibMain, (PVOID)&_Resource_PEResTab);
178 if(dllHandle == 0)
179 return 0UL;
180
181 break;
182 case 1 :
183 if(hTWAIN)
184#if 0
185 FreeLibrary(hTWAIN);
186#else
187 DosFreeModule(hTWAIN);
188#endif
189 hTWAIN = 0;
190 if(dllHandle) {
191 UnregisterLxDll(dllHandle);
192 }
193 break;
194 default :
195 return 0UL;
196 }
197
198 /***********************************************************/
199 /* A non-zero value must be returned to indicate success. */
200 /***********************************************************/
201 return 1UL;
202}
203//******************************************************************************
204//******************************************************************************
Note: See TracBrowser for help on using the repository browser.