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

Last change on this file since 10367 was 6650, checked in by bird, 24 years ago

Added $Id:$ keyword.

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