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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
30 TWAIN_LibMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
32 TRACE("%x,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
36 case DLL_PROCESS_ATTACH
:
40 case DLL_THREAD_ATTACH
:
43 case DLL_THREAD_DETACH
:
46 case DLL_PROCESS_DETACH
:
54 TW_UINT16
TWAIN_SourceManagerHandler (
60 TW_UINT16 twRC
= TWRC_SUCCESS
;
68 twRC
= TWAIN_CloseDS (pOrigin
, pData
);
72 twRC
= TWAIN_IdentityGetDefault (pOrigin
, pData
);
76 twRC
= TWAIN_IdentityGetFirst (pOrigin
, pData
);
80 twRC
= TWAIN_IdentityGetNext (pOrigin
, pData
);
84 twRC
= TWAIN_OpenDS (pOrigin
, pData
);
88 twRC
= TWAIN_UserSelect (pOrigin
, pData
);
92 /* Unrecognized operation triplet */
94 DSM_twCC
= TWCC_BADPROTOCOL
;
95 WARN("unrecognized operation triplet\n");
104 twRC
= TWAIN_CloseDSM (pOrigin
, pData
);
108 twRC
= TWAIN_OpenDSM (pOrigin
, pData
);
112 /* Unrecognized operation triplet */
114 DSM_twCC
= TWCC_BADPROTOCOL
;
115 WARN("unrecognized operation triplet\n");
122 twRC
= TWAIN_GetDSMStatus (pOrigin
, pData
);
127 DSM_twCC
= TWCC_BADPROTOCOL
;
128 WARN("unrecognized operation triplet\n");
134 DSM_twCC
= TWCC_BADPROTOCOL
;
135 WARN("unrecognized operation triplet\n");
142 TW_UINT16
TWAIN_SourceControlHandler (
143 pTW_IDENTITY pOrigin
,
149 TW_UINT16 twRC
= TWRC_SUCCESS
;
157 twRC
= TWAIN_CapabilityGet (pOrigin
, pDest
, pData
);
160 twRC
= TWAIN_CapabilityGetCurrent (pOrigin
, pDest
, pData
);
163 twRC
= TWAIN_CapabilityGetDefault (pOrigin
, pDest
, pData
);
165 case MSG_QUERYSUPPORT
:
166 twRC
= TWAIN_CapabilityQuerySupport (pOrigin
, pDest
, pData
);
169 twRC
= TWAIN_CapabilityReset (pOrigin
, pDest
, pData
);
172 twRC
= TWAIN_CapabilitySet (pOrigin
, pDest
, pData
);
176 WARN("unrecognized opertion triplet\n");
180 case DAT_CUSTOMDSDATA
:
184 twRC
= TWAIN_CustomDSDataGet (pOrigin
, pDest
, pData
);
187 twRC
= TWAIN_CustomDSDataSet (pOrigin
, pDest
, pData
);
197 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
198 twRC = TWAIN_AutomaticCaptureDirectory
199 (pOrigin, pDest, pData);
201 case MSG_CHANGEDIRECTORY
:
202 twRC
= TWAIN_ChangeDirectory (pOrigin
, pDest
, pData
);
205 twRC = TWAIN_FileSystemCopy (pOrigin, pDest, pData);
207 case MSG_CREATEDIRECTORY
:
208 twRC
= TWAIN_CreateDirectory (pOrigin
, pDest
, pData
);
211 twRC
= TWAIN_FileSystemDelete (pOrigin
, pDest
, pData
);
213 case MSG_FORMATMEDIA
:
214 twRC
= TWAIN_FormatMedia (pOrigin
, pDest
, pData
);
217 twRC
= TWAIN_FileSystemGetClose (pOrigin
, pDest
, pData
);
219 case MSG_GETFIRSTFILE
:
220 twRC
= TWAIN_FileSystemGetFirstFile
221 (pOrigin
, pDest
, pData
);
224 twRC
= TWAIN_FileSystemGetInfo (pOrigin
, pDest
, pData
);
226 case MSG_GETNEXTFILE
:
227 twRC
= TWAIN_FileSystemGetNextFile
228 (pOrigin
, pDest
, pData
);
231 twRC
= TWAIN_FileSystemRename (pOrigin
, pDest
, pData
);
240 if (MSG
== MSG_PROCESSEVENT
)
241 twRC
= TWAIN_ProcessEvent (pOrigin
, pDest
, pData
);
247 if (MSG
== MSG_PASSTHRU
)
248 twRC
= TWAIN_PassThrough (pOrigin
, pDest
, pData
);
253 case DAT_PENDINGXFERS
:
257 twRC
= TWAIN_PendingXfersEndXfer (pOrigin
, pDest
, pData
);
260 twRC
= TWAIN_PendingXfersGet (pOrigin
, pDest
, pData
);
263 twRC
= TWAIN_PendingXfersReset (pOrigin
, pDest
, pData
);
265 /*case MSG_STOPFEEDER:
266 twRC = TWAIN_PendingXfersStopFeeder
267 (pOrigin, pDest, pData);
274 case DAT_SETUPFILEXFER
:
278 twRC
= TWAIN_SetupFileXferGet (pOrigin
, pDest
, pData
);
281 twRC
= TWAIN_SetupFileXferGetDefault
282 (pOrigin
, pDest
, pData
);
285 twRC
= TWAIN_SetupFileXferReset (pOrigin
, pDest
, pData
);
288 twRC
= TWAIN_SetupFileXferSet (pOrigin
, pDest
, pData
);
296 /*case DAT_SETUPFILEXFER2:
300 twRC = TWAIN_SetupFileXfer2Get (pOrigin, pDest, pData);
303 twRC = TWAIN_SetupFileXfer2GetDefault
304 (pOrigin, pDest, pData);
307 twRC = TWAIN_SetupFileXfer2Reset (pOrigin, pDest, pData);
310 twRC = TWAIN_SetupFileXfer2Set (pOrigin, pDest, pData);
314 case DAT_SETUPMEMXFER
:
316 twRC
= TWAIN_SetupMemXferGet (pOrigin
, pDest
, pData
);
323 twRC
= TWAIN_GetDSStatus (pOrigin
, pDest
, pData
);
328 case DAT_USERINTERFACE
:
332 twRC
= TWAIN_DisableDSUserInterface
333 (pOrigin
, pDest
, pData
);
336 twRC
= TWAIN_EnableDSUserInterface
337 (pOrigin
, pDest
, pData
);
339 case MSG_ENABLEDSUIONLY
:
340 twRC
= TWAIN_EnableDSUIOnly (pOrigin
, pDest
, pData
);
352 twRC
= TWAIN_XferGroupGet (pOrigin
, pDest
, pData
);
355 twRC
= TWAIN_XferGroupSet (pOrigin
, pDest
, pData
);
371 TW_UINT16
TWAIN_ControlGroupHandler (
372 pTW_IDENTITY pOrigin
,
378 TW_UINT16 twRC
= TWRC_SUCCESS
;
382 /* This operation's destination is a source */
383 twRC
= TWAIN_SourceControlHandler (pOrigin
, pDest
, DAT
, MSG
, pData
);
387 /* This operation's destination is the Source Manager */
388 twRC
= TWAIN_SourceManagerHandler (pOrigin
, DAT
, MSG
, pData
);
394 TW_UINT16
TWAIN_ImageGroupHandler (
395 pTW_IDENTITY pOrigin
,
401 TW_UINT16 twRC
= TWRC_SUCCESS
;
405 DSM_twCC
= TWCC_BADDEST
;
413 twRC
= TWAIN_CIEColorGet (pOrigin
, pDest
, pData
);
418 case DAT_EXTIMAGEINFO
:
420 twRC
= TWAIN_ExtImageInfoGet (pOrigin
, pDest
, pData
);
425 case DAT_GRAYRESPONSE
:
429 twRC
= TWAIN_GrayResponseReset (pOrigin
, pDest
, pData
);
432 twRC
= TWAIN_GrayResponseSet (pOrigin
, pDest
, pData
);
436 DSM_twCC
= TWCC_BADPROTOCOL
;
437 WARN("unrecognized operation triplet\n");
441 case DAT_IMAGEFILEXFER
:
443 twRC
= TWAIN_ImageFileXferGet (pOrigin
, pDest
, pData
);
450 twRC
= TWAIN_ImageInfoGet (pOrigin
, pDest
, pData
);
455 case DAT_IMAGELAYOUT
:
459 twRC
= TWAIN_ImageLayoutGet (pOrigin
, pDest
, pData
);
462 twRC
= TWAIN_ImageLayoutGetDefault (pOrigin
, pDest
, pData
);
465 twRC
= TWAIN_ImageLayoutReset (pOrigin
, pDest
, pData
);
468 twRC
= TWAIN_ImageLayoutSet (pOrigin
, pDest
, pData
);
472 DSM_twCC
= TWCC_BADPROTOCOL
;
473 WARN("unrecognized operation triplet\n");
478 case DAT_IMAGEMEMXFER
:
480 twRC
= TWAIN_ImageMemXferGet (pOrigin
, pDest
, pData
);
485 case DAT_IMAGENATIVEXFER
:
487 twRC
= TWAIN_ImageNativeXferGet (pOrigin
, pDest
, pData
);
492 case DAT_JPEGCOMPRESSION
:
496 twRC
= TWAIN_JPEGCompressionGet (pOrigin
, pDest
, pData
);
499 twRC
= TWAIN_JPEGCompressionGetDefault
500 (pOrigin
, pDest
, pData
);
503 twRC
= TWAIN_JPEGCompressionReset (pOrigin
, pDest
, pData
);
506 twRC
= TWAIN_JPEGCompressionSet (pOrigin
, pDest
, pData
);
510 DSM_twCC
= TWCC_BADPROTOCOL
;
511 WARN("unrecognized operation triplet\n");
520 twRC
= TWAIN_Palette8Get (pOrigin
, pDest
, pData
);
523 twRC
= TWAIN_Palette8GetDefault (pOrigin
, pDest
, pData
);
526 twRC
= TWAIN_Palette8Reset (pOrigin
, pDest
, pData
);
529 twRC
= TWAIN_Palette8Set (pOrigin
, pDest
, pData
);
533 DSM_twCC
= TWCC_BADPROTOCOL
;
534 WARN("unrecognized operation triplet\n");
538 case DAT_RGBRESPONSE
:
542 twRC
= TWAIN_RGBResponseReset (pOrigin
, pDest
, pData
);
545 twRC
= TWAIN_RGBResponseSet (pOrigin
, pDest
, pData
);
549 DSM_twCC
= TWCC_BADPROTOCOL
;
550 WARN("unrecognized operation triplet\n");
557 DSM_twCC
= TWCC_BADPROTOCOL
;
558 WARN("unrecognized operation triplet\n");
563 TW_UINT16
TWAIN_AudioGroupHandler (
564 pTW_IDENTITY pOrigin
,
570 TW_UINT16 twRC
= TWRC_FAILURE
;
574 case DAT_AUDIOFILEXFER
:
576 twRC
= TWAIN_AudioFileXferGet (pOrigin
, pDest
, pData
);
581 twRC
= TWAIN_AudioInfoGet (pOrigin
, pDest
, pData
);
584 case DAT_AUDIONATIVEXFER
:
586 twRC
= TWAIN_AudioNativeXferGet (pOrigin
, pDest
, pData
);
590 DSM_twCC
= TWCC_BADPROTOCOL
;
598 /* Main entry point for the TWAIN library */
600 DSM_Entry (pTW_IDENTITY pOrigin
,
607 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
609 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
614 twRC
= TWAIN_ControlGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
617 twRC
= TWAIN_ImageGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
620 twRC
= TWAIN_AudioGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
623 DSM_twCC
= TWCC_BADPROTOCOL
;
630 /* A helper function that looks up a destination identity in the active
632 activeDS
*TWAIN_LookupSource (pTW_IDENTITY pDest
)
636 for (pSource
= activeSources
; pSource
; pSource
= pSource
->next
)
637 if (pSource
->identity
.Id
== pDest
->Id
)