4 * Copyright 2000 Shi Quan He <shiquan@cyberdude.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
29 struct tagActiveDS activeDS
;
31 DSMENTRYPROC SANE_dsmentry
;
32 HINSTANCE SANE_instance
;
34 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
36 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
40 case DLL_PROCESS_ATTACH
: {
41 SANE_instance
= hinstDLL
;
42 DisableThreadLibraryCalls(hinstDLL
);
43 if (__wine_init_unix_call()) return FALSE
;
44 SANE_CALL( process_attach
, NULL
);
47 case DLL_PROCESS_DETACH
:
48 if (lpvReserved
) break;
49 SANE_CALL( process_detach
, NULL
);
56 static TW_UINT16
SANE_OpenDS( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
)
58 if (SANE_dsmentry
== NULL
)
60 HMODULE moddsm
= GetModuleHandleW(L
"twain_32");
63 SANE_dsmentry
= (void*)GetProcAddress(moddsm
, "DSM_Entry");
67 ERR("can't find DSM entry point\n");
72 if (SANE_CALL( open_ds
, self
)) return TWRC_FAILURE
;
74 activeDS
.twCC
= SANE_SaneSetDefaults();
75 if (activeDS
.twCC
== TWCC_SUCCESS
)
77 activeDS
.currentState
= 4;
78 activeDS
.identity
.Id
= self
->Id
;
79 activeDS
.appIdentity
= *pOrigin
;
82 SANE_CALL( close_ds
, NULL
);
86 static TW_UINT16
SANE_SetEntryPoint (pTW_IDENTITY pOrigin
, TW_MEMREF pData
);
88 static TW_UINT16
SANE_SourceControlHandler (
94 TW_UINT16 twRC
= TWRC_SUCCESS
;
102 SANE_CALL( close_ds
, NULL
);
105 twRC
= SANE_OpenDS( pOrigin
, (pTW_IDENTITY
)pData
);
109 if (SANE_CALL( get_identity
, pData
))
111 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
122 twRC
= SANE_CapabilityGet (pOrigin
, pData
);
125 twRC
= SANE_CapabilityGetCurrent (pOrigin
, pData
);
128 twRC
= SANE_CapabilityGetDefault (pOrigin
, pData
);
130 case MSG_QUERYSUPPORT
:
131 twRC
= SANE_CapabilityQuerySupport (pOrigin
, pData
);
134 twRC
= SANE_CapabilityReset (pOrigin
, pData
);
137 twRC
= SANE_CapabilitySet (pOrigin
, pData
);
141 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
142 FIXME("unrecognized operation triplet\n");
149 twRC
= SANE_SetEntryPoint (pOrigin
, pData
);
153 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
154 FIXME("unrecognized operation triplet\n");
159 if (MSG
== MSG_PROCESSEVENT
)
160 twRC
= SANE_ProcessEvent (pOrigin
, pData
);
163 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
168 case DAT_PENDINGXFERS
:
172 twRC
= SANE_PendingXfersEndXfer (pOrigin
, pData
);
175 twRC
= SANE_PendingXfersGet (pOrigin
, pData
);
178 twRC
= SANE_PendingXfersReset (pOrigin
, pData
);
181 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
186 case DAT_SETUPMEMXFER
:
188 twRC
= SANE_SetupMemXferGet (pOrigin
, pData
);
191 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
198 twRC
= SANE_GetDSStatus (pOrigin
, pData
);
201 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
206 case DAT_USERINTERFACE
:
210 twRC
= SANE_DisableDSUserInterface (pOrigin
, pData
);
213 twRC
= SANE_EnableDSUserInterface (pOrigin
, pData
);
215 case MSG_ENABLEDSUIONLY
:
216 twRC
= SANE_EnableDSUIOnly (pOrigin
, pData
);
219 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
229 twRC
= SANE_XferGroupGet (pOrigin
, pData
);
232 twRC
= SANE_XferGroupSet (pOrigin
, pData
);
235 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
242 WARN("code unsupported: %d\n", DAT
);
243 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
252 static TW_UINT16
SANE_ImageGroupHandler (
253 pTW_IDENTITY pOrigin
,
258 TW_UINT16 twRC
= TWRC_SUCCESS
;
264 twRC
= SANE_ImageInfoGet (pOrigin
, pData
);
267 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
272 case DAT_IMAGELAYOUT
:
276 twRC
= SANE_ImageLayoutGet (pOrigin
, pData
);
279 twRC
= SANE_ImageLayoutGetDefault (pOrigin
, pData
);
282 twRC
= SANE_ImageLayoutReset (pOrigin
, pData
);
285 twRC
= SANE_ImageLayoutSet (pOrigin
, pData
);
289 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
290 ERR("unrecognized operation triplet\n");
295 case DAT_IMAGEMEMXFER
:
297 twRC
= SANE_ImageMemXferGet (pOrigin
, pData
);
300 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
305 case DAT_IMAGENATIVEXFER
:
307 twRC
= SANE_ImageNativeXferGet (pOrigin
, pData
);
310 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
317 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
318 WARN("unsupported DG type %d\n", DAT
);
324 /* Main entry point for the TWAIN library */
326 DS_Entry ( pTW_IDENTITY pOrigin
,
332 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
334 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
339 twRC
= SANE_SourceControlHandler (pOrigin
,DAT
,MSG
,pData
);
342 twRC
= SANE_ImageGroupHandler (pOrigin
,DAT
,MSG
,pData
);
345 WARN("Audio group of controls not implemented yet.\n");
347 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
350 activeDS
.twCC
= TWCC_BADPROTOCOL
;
357 void SANE_Notify (TW_UINT16 message
)
359 SANE_dsmentry (&activeDS
.identity
, &activeDS
.appIdentity
, DG_CONTROL
, DAT_NULL
, message
, NULL
);
362 /* DG_CONTROL/DAT_ENTRYPOINT/MSG_SET */
363 TW_UINT16
SANE_SetEntryPoint (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
365 TW_ENTRYPOINT
*entry
= (TW_ENTRYPOINT
*)pData
;
367 SANE_dsmentry
= entry
->DSM_Entry
;