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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
31 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
33 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
37 case DLL_PROCESS_ATTACH
:
38 DisableThreadLibraryCalls(hinstDLL
);
42 case DLL_PROCESS_DETACH
:
50 TW_UINT16
TWAIN_SourceManagerHandler (
56 TW_UINT16 twRC
= TWRC_SUCCESS
;
64 twRC
= TWAIN_CloseDS (pOrigin
, pData
);
68 twRC
= TWAIN_IdentityGetDefault (pOrigin
, pData
);
72 twRC
= TWAIN_IdentityGetFirst (pOrigin
, pData
);
76 twRC
= TWAIN_IdentityGetNext (pOrigin
, pData
);
80 twRC
= TWAIN_OpenDS (pOrigin
, pData
);
84 twRC
= TWAIN_UserSelect (pOrigin
, pData
);
88 /* Unrecognized operation triplet */
90 DSM_twCC
= TWCC_BADPROTOCOL
;
91 WARN("unrecognized operation triplet\n");
100 twRC
= TWAIN_CloseDSM (pOrigin
, pData
);
104 twRC
= TWAIN_OpenDSM (pOrigin
, pData
);
108 /* Unrecognized operation triplet */
110 DSM_twCC
= TWCC_BADPROTOCOL
;
111 WARN("unrecognized operation triplet\n");
118 twRC
= TWAIN_GetDSMStatus (pOrigin
, pData
);
123 DSM_twCC
= TWCC_BADPROTOCOL
;
124 WARN("unrecognized operation triplet\n");
130 DSM_twCC
= TWCC_BADPROTOCOL
;
131 WARN("unrecognized operation triplet\n");
138 TW_UINT16
TWAIN_SourceControlHandler (
139 pTW_IDENTITY pOrigin
,
145 TW_UINT16 twRC
= TWRC_SUCCESS
;
153 twRC
= TWAIN_CapabilityGet (pOrigin
, pDest
, pData
);
156 twRC
= TWAIN_CapabilityGetCurrent (pOrigin
, pDest
, pData
);
159 twRC
= TWAIN_CapabilityGetDefault (pOrigin
, pDest
, pData
);
161 case MSG_QUERYSUPPORT
:
162 twRC
= TWAIN_CapabilityQuerySupport (pOrigin
, pDest
, pData
);
165 twRC
= TWAIN_CapabilityReset (pOrigin
, pDest
, pData
);
168 twRC
= TWAIN_CapabilitySet (pOrigin
, pDest
, pData
);
172 WARN("unrecognized opertion triplet\n");
176 case DAT_CUSTOMDSDATA
:
180 twRC
= TWAIN_CustomDSDataGet (pOrigin
, pDest
, pData
);
183 twRC
= TWAIN_CustomDSDataSet (pOrigin
, pDest
, pData
);
193 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
194 twRC = TWAIN_AutomaticCaptureDirectory
195 (pOrigin, pDest, pData);
197 case MSG_CHANGEDIRECTORY
:
198 twRC
= TWAIN_ChangeDirectory (pOrigin
, pDest
, pData
);
201 twRC = TWAIN_FileSystemCopy (pOrigin, pDest, pData);
203 case MSG_CREATEDIRECTORY
:
204 twRC
= TWAIN_CreateDirectory (pOrigin
, pDest
, pData
);
207 twRC
= TWAIN_FileSystemDelete (pOrigin
, pDest
, pData
);
209 case MSG_FORMATMEDIA
:
210 twRC
= TWAIN_FormatMedia (pOrigin
, pDest
, pData
);
213 twRC
= TWAIN_FileSystemGetClose (pOrigin
, pDest
, pData
);
215 case MSG_GETFIRSTFILE
:
216 twRC
= TWAIN_FileSystemGetFirstFile
217 (pOrigin
, pDest
, pData
);
220 twRC
= TWAIN_FileSystemGetInfo (pOrigin
, pDest
, pData
);
222 case MSG_GETNEXTFILE
:
223 twRC
= TWAIN_FileSystemGetNextFile
224 (pOrigin
, pDest
, pData
);
227 twRC
= TWAIN_FileSystemRename (pOrigin
, pDest
, pData
);
236 if (MSG
== MSG_PROCESSEVENT
)
237 twRC
= TWAIN_ProcessEvent (pOrigin
, pDest
, pData
);
243 if (MSG
== MSG_PASSTHRU
)
244 twRC
= TWAIN_PassThrough (pOrigin
, pDest
, pData
);
249 case DAT_PENDINGXFERS
:
253 twRC
= TWAIN_PendingXfersEndXfer (pOrigin
, pDest
, pData
);
256 twRC
= TWAIN_PendingXfersGet (pOrigin
, pDest
, pData
);
259 twRC
= TWAIN_PendingXfersReset (pOrigin
, pDest
, pData
);
261 /*case MSG_STOPFEEDER:
262 twRC = TWAIN_PendingXfersStopFeeder
263 (pOrigin, pDest, pData);
270 case DAT_SETUPFILEXFER
:
274 twRC
= TWAIN_SetupFileXferGet (pOrigin
, pDest
, pData
);
277 twRC
= TWAIN_SetupFileXferGetDefault
278 (pOrigin
, pDest
, pData
);
281 twRC
= TWAIN_SetupFileXferReset (pOrigin
, pDest
, pData
);
284 twRC
= TWAIN_SetupFileXferSet (pOrigin
, pDest
, pData
);
292 /*case DAT_SETUPFILEXFER2:
296 twRC = TWAIN_SetupFileXfer2Get (pOrigin, pDest, pData);
299 twRC = TWAIN_SetupFileXfer2GetDefault
300 (pOrigin, pDest, pData);
303 twRC = TWAIN_SetupFileXfer2Reset (pOrigin, pDest, pData);
306 twRC = TWAIN_SetupFileXfer2Set (pOrigin, pDest, pData);
310 case DAT_SETUPMEMXFER
:
312 twRC
= TWAIN_SetupMemXferGet (pOrigin
, pDest
, pData
);
319 twRC
= TWAIN_GetDSStatus (pOrigin
, pDest
, pData
);
324 case DAT_USERINTERFACE
:
328 twRC
= TWAIN_DisableDSUserInterface
329 (pOrigin
, pDest
, pData
);
332 twRC
= TWAIN_EnableDSUserInterface
333 (pOrigin
, pDest
, pData
);
335 case MSG_ENABLEDSUIONLY
:
336 twRC
= TWAIN_EnableDSUIOnly (pOrigin
, pDest
, pData
);
348 twRC
= TWAIN_XferGroupGet (pOrigin
, pDest
, pData
);
351 twRC
= TWAIN_XferGroupSet (pOrigin
, pDest
, pData
);
367 TW_UINT16
TWAIN_ControlGroupHandler (
368 pTW_IDENTITY pOrigin
,
374 TW_UINT16 twRC
= TWRC_SUCCESS
;
378 /* This operation's destination is a source */
379 twRC
= TWAIN_SourceControlHandler (pOrigin
, pDest
, DAT
, MSG
, pData
);
383 /* This operation's destination is the Source Manager */
384 twRC
= TWAIN_SourceManagerHandler (pOrigin
, DAT
, MSG
, pData
);
390 TW_UINT16
TWAIN_ImageGroupHandler (
391 pTW_IDENTITY pOrigin
,
397 TW_UINT16 twRC
= TWRC_SUCCESS
;
401 DSM_twCC
= TWCC_BADDEST
;
409 twRC
= TWAIN_CIEColorGet (pOrigin
, pDest
, pData
);
414 case DAT_EXTIMAGEINFO
:
416 twRC
= TWAIN_ExtImageInfoGet (pOrigin
, pDest
, pData
);
421 case DAT_GRAYRESPONSE
:
425 twRC
= TWAIN_GrayResponseReset (pOrigin
, pDest
, pData
);
428 twRC
= TWAIN_GrayResponseSet (pOrigin
, pDest
, pData
);
432 DSM_twCC
= TWCC_BADPROTOCOL
;
433 WARN("unrecognized operation triplet\n");
437 case DAT_IMAGEFILEXFER
:
439 twRC
= TWAIN_ImageFileXferGet (pOrigin
, pDest
, pData
);
446 twRC
= TWAIN_ImageInfoGet (pOrigin
, pDest
, pData
);
451 case DAT_IMAGELAYOUT
:
455 twRC
= TWAIN_ImageLayoutGet (pOrigin
, pDest
, pData
);
458 twRC
= TWAIN_ImageLayoutGetDefault (pOrigin
, pDest
, pData
);
461 twRC
= TWAIN_ImageLayoutReset (pOrigin
, pDest
, pData
);
464 twRC
= TWAIN_ImageLayoutSet (pOrigin
, pDest
, pData
);
468 DSM_twCC
= TWCC_BADPROTOCOL
;
469 WARN("unrecognized operation triplet\n");
474 case DAT_IMAGEMEMXFER
:
476 twRC
= TWAIN_ImageMemXferGet (pOrigin
, pDest
, pData
);
481 case DAT_IMAGENATIVEXFER
:
483 twRC
= TWAIN_ImageNativeXferGet (pOrigin
, pDest
, pData
);
488 case DAT_JPEGCOMPRESSION
:
492 twRC
= TWAIN_JPEGCompressionGet (pOrigin
, pDest
, pData
);
495 twRC
= TWAIN_JPEGCompressionGetDefault
496 (pOrigin
, pDest
, pData
);
499 twRC
= TWAIN_JPEGCompressionReset (pOrigin
, pDest
, pData
);
502 twRC
= TWAIN_JPEGCompressionSet (pOrigin
, pDest
, pData
);
506 DSM_twCC
= TWCC_BADPROTOCOL
;
507 WARN("unrecognized operation triplet\n");
516 twRC
= TWAIN_Palette8Get (pOrigin
, pDest
, pData
);
519 twRC
= TWAIN_Palette8GetDefault (pOrigin
, pDest
, pData
);
522 twRC
= TWAIN_Palette8Reset (pOrigin
, pDest
, pData
);
525 twRC
= TWAIN_Palette8Set (pOrigin
, pDest
, pData
);
529 DSM_twCC
= TWCC_BADPROTOCOL
;
530 WARN("unrecognized operation triplet\n");
534 case DAT_RGBRESPONSE
:
538 twRC
= TWAIN_RGBResponseReset (pOrigin
, pDest
, pData
);
541 twRC
= TWAIN_RGBResponseSet (pOrigin
, pDest
, pData
);
545 DSM_twCC
= TWCC_BADPROTOCOL
;
546 WARN("unrecognized operation triplet\n");
553 DSM_twCC
= TWCC_BADPROTOCOL
;
554 WARN("unrecognized operation triplet\n");
559 TW_UINT16
TWAIN_AudioGroupHandler (
560 pTW_IDENTITY pOrigin
,
566 TW_UINT16 twRC
= TWRC_FAILURE
;
570 case DAT_AUDIOFILEXFER
:
572 twRC
= TWAIN_AudioFileXferGet (pOrigin
, pDest
, pData
);
577 twRC
= TWAIN_AudioInfoGet (pOrigin
, pDest
, pData
);
580 case DAT_AUDIONATIVEXFER
:
582 twRC
= TWAIN_AudioNativeXferGet (pOrigin
, pDest
, pData
);
586 DSM_twCC
= TWCC_BADPROTOCOL
;
594 /* Main entry point for the TWAIN library */
596 DSM_Entry (pTW_IDENTITY pOrigin
,
603 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
605 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
610 twRC
= TWAIN_ControlGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
613 twRC
= TWAIN_ImageGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
616 twRC
= TWAIN_AudioGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
619 DSM_twCC
= TWCC_BADPROTOCOL
;
626 /* A helper function that looks up a destination identity in the active
628 activeDS
*TWAIN_LookupSource (pTW_IDENTITY pDest
)
632 for (pSource
= activeSources
; pSource
; pSource
= pSource
->next
)
633 if (pSource
->identity
.Id
== pDest
->Id
)