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
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(twain);
33 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
35 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
39 case DLL_PROCESS_ATTACH:
40 DisableThreadLibraryCalls(hinstDLL);
44 case DLL_PROCESS_DETACH:
52 TW_UINT16 TWAIN_SourceManagerHandler (
58 TW_UINT16 twRC = TWRC_SUCCESS;
66 twRC = TWAIN_CloseDS (pOrigin, pData);
70 twRC = TWAIN_IdentityGetDefault (pOrigin, pData);
74 twRC = TWAIN_IdentityGetFirst (pOrigin, pData);
78 twRC = TWAIN_IdentityGetNext (pOrigin, pData);
82 twRC = TWAIN_OpenDS (pOrigin, pData);
86 twRC = TWAIN_UserSelect (pOrigin, pData);
90 /* Unrecognized operation triplet */
92 DSM_twCC = TWCC_BADPROTOCOL;
93 WARN("unrecognized operation triplet\n");
102 twRC = TWAIN_CloseDSM (pOrigin, pData);
106 twRC = TWAIN_OpenDSM (pOrigin, pData);
110 /* Unrecognized operation triplet */
112 DSM_twCC = TWCC_BADPROTOCOL;
113 WARN("unrecognized operation triplet\n");
120 twRC = TWAIN_GetDSMStatus (pOrigin, pData);
125 DSM_twCC = TWCC_BADPROTOCOL;
126 WARN("unrecognized operation triplet\n");
132 DSM_twCC = TWCC_BADPROTOCOL;
133 WARN("unrecognized operation triplet\n");
140 TW_UINT16 TWAIN_SourceControlHandler (
141 pTW_IDENTITY pOrigin,
147 TW_UINT16 twRC = TWRC_SUCCESS;
155 twRC = TWAIN_CapabilityGet (pOrigin, pDest, pData);
158 twRC = TWAIN_CapabilityGetCurrent (pOrigin, pDest, pData);
161 twRC = TWAIN_CapabilityGetDefault (pOrigin, pDest, pData);
163 case MSG_QUERYSUPPORT:
164 twRC = TWAIN_CapabilityQuerySupport (pOrigin, pDest, pData);
167 twRC = TWAIN_CapabilityReset (pOrigin, pDest, pData);
170 twRC = TWAIN_CapabilitySet (pOrigin, pDest, pData);
174 WARN("unrecognized opertion triplet\n");
178 case DAT_CUSTOMDSDATA:
182 twRC = TWAIN_CustomDSDataGet (pOrigin, pDest, pData);
185 twRC = TWAIN_CustomDSDataSet (pOrigin, pDest, pData);
195 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
196 twRC = TWAIN_AutomaticCaptureDirectory
197 (pOrigin, pDest, pData);
199 case MSG_CHANGEDIRECTORY:
200 twRC = TWAIN_ChangeDirectory (pOrigin, pDest, pData);
203 twRC = TWAIN_FileSystemCopy (pOrigin, pDest, pData);
205 case MSG_CREATEDIRECTORY:
206 twRC = TWAIN_CreateDirectory (pOrigin, pDest, pData);
209 twRC = TWAIN_FileSystemDelete (pOrigin, pDest, pData);
211 case MSG_FORMATMEDIA:
212 twRC = TWAIN_FormatMedia (pOrigin, pDest, pData);
215 twRC = TWAIN_FileSystemGetClose (pOrigin, pDest, pData);
217 case MSG_GETFIRSTFILE:
218 twRC = TWAIN_FileSystemGetFirstFile
219 (pOrigin, pDest, pData);
222 twRC = TWAIN_FileSystemGetInfo (pOrigin, pDest, pData);
224 case MSG_GETNEXTFILE:
225 twRC = TWAIN_FileSystemGetNextFile
226 (pOrigin, pDest, pData);
229 twRC = TWAIN_FileSystemRename (pOrigin, pDest, pData);
238 if (MSG == MSG_PROCESSEVENT)
239 twRC = TWAIN_ProcessEvent (pOrigin, pDest, pData);
245 if (MSG == MSG_PASSTHRU)
246 twRC = TWAIN_PassThrough (pOrigin, pDest, pData);
251 case DAT_PENDINGXFERS:
255 twRC = TWAIN_PendingXfersEndXfer (pOrigin, pDest, pData);
258 twRC = TWAIN_PendingXfersGet (pOrigin, pDest, pData);
261 twRC = TWAIN_PendingXfersReset (pOrigin, pDest, pData);
263 /*case MSG_STOPFEEDER:
264 twRC = TWAIN_PendingXfersStopFeeder
265 (pOrigin, pDest, pData);
272 case DAT_SETUPFILEXFER:
276 twRC = TWAIN_SetupFileXferGet (pOrigin, pDest, pData);
279 twRC = TWAIN_SetupFileXferGetDefault
280 (pOrigin, pDest, pData);
283 twRC = TWAIN_SetupFileXferReset (pOrigin, pDest, pData);
286 twRC = TWAIN_SetupFileXferSet (pOrigin, pDest, pData);
294 /*case DAT_SETUPFILEXFER2:
298 twRC = TWAIN_SetupFileXfer2Get (pOrigin, pDest, pData);
301 twRC = TWAIN_SetupFileXfer2GetDefault
302 (pOrigin, pDest, pData);
305 twRC = TWAIN_SetupFileXfer2Reset (pOrigin, pDest, pData);
308 twRC = TWAIN_SetupFileXfer2Set (pOrigin, pDest, pData);
312 case DAT_SETUPMEMXFER:
314 twRC = TWAIN_SetupMemXferGet (pOrigin, pDest, pData);
321 twRC = TWAIN_GetDSStatus (pOrigin, pDest, pData);
326 case DAT_USERINTERFACE:
330 twRC = TWAIN_DisableDSUserInterface
331 (pOrigin, pDest, pData);
334 twRC = TWAIN_EnableDSUserInterface
335 (pOrigin, pDest, pData);
337 case MSG_ENABLEDSUIONLY:
338 twRC = TWAIN_EnableDSUIOnly (pOrigin, pDest, pData);
350 twRC = TWAIN_XferGroupGet (pOrigin, pDest, pData);
353 twRC = TWAIN_XferGroupSet (pOrigin, pDest, pData);
369 TW_UINT16 TWAIN_ControlGroupHandler (
370 pTW_IDENTITY pOrigin,
376 TW_UINT16 twRC = TWRC_SUCCESS;
380 /* This operation's destination is a source */
381 twRC = TWAIN_SourceControlHandler (pOrigin, pDest, DAT, MSG, pData);
385 /* This operation's destination is the Source Manager */
386 twRC = TWAIN_SourceManagerHandler (pOrigin, DAT, MSG, pData);
392 TW_UINT16 TWAIN_ImageGroupHandler (
393 pTW_IDENTITY pOrigin,
399 TW_UINT16 twRC = TWRC_SUCCESS;
403 DSM_twCC = TWCC_BADDEST;
411 twRC = TWAIN_CIEColorGet (pOrigin, pDest, pData);
416 case DAT_EXTIMAGEINFO:
418 twRC = TWAIN_ExtImageInfoGet (pOrigin, pDest, pData);
423 case DAT_GRAYRESPONSE:
427 twRC = TWAIN_GrayResponseReset (pOrigin, pDest, pData);
430 twRC = TWAIN_GrayResponseSet (pOrigin, pDest, pData);
434 DSM_twCC = TWCC_BADPROTOCOL;
435 WARN("unrecognized operation triplet\n");
439 case DAT_IMAGEFILEXFER:
441 twRC = TWAIN_ImageFileXferGet (pOrigin, pDest, pData);
448 twRC = TWAIN_ImageInfoGet (pOrigin, pDest, pData);
453 case DAT_IMAGELAYOUT:
457 twRC = TWAIN_ImageLayoutGet (pOrigin, pDest, pData);
460 twRC = TWAIN_ImageLayoutGetDefault (pOrigin, pDest, pData);
463 twRC = TWAIN_ImageLayoutReset (pOrigin, pDest, pData);
466 twRC = TWAIN_ImageLayoutSet (pOrigin, pDest, pData);
470 DSM_twCC = TWCC_BADPROTOCOL;
471 WARN("unrecognized operation triplet\n");
476 case DAT_IMAGEMEMXFER:
478 twRC = TWAIN_ImageMemXferGet (pOrigin, pDest, pData);
483 case DAT_IMAGENATIVEXFER:
485 twRC = TWAIN_ImageNativeXferGet (pOrigin, pDest, pData);
490 case DAT_JPEGCOMPRESSION:
494 twRC = TWAIN_JPEGCompressionGet (pOrigin, pDest, pData);
497 twRC = TWAIN_JPEGCompressionGetDefault
498 (pOrigin, pDest, pData);
501 twRC = TWAIN_JPEGCompressionReset (pOrigin, pDest, pData);
504 twRC = TWAIN_JPEGCompressionSet (pOrigin, pDest, pData);
508 DSM_twCC = TWCC_BADPROTOCOL;
509 WARN("unrecognized operation triplet\n");
518 twRC = TWAIN_Palette8Get (pOrigin, pDest, pData);
521 twRC = TWAIN_Palette8GetDefault (pOrigin, pDest, pData);
524 twRC = TWAIN_Palette8Reset (pOrigin, pDest, pData);
527 twRC = TWAIN_Palette8Set (pOrigin, pDest, pData);
531 DSM_twCC = TWCC_BADPROTOCOL;
532 WARN("unrecognized operation triplet\n");
536 case DAT_RGBRESPONSE:
540 twRC = TWAIN_RGBResponseReset (pOrigin, pDest, pData);
543 twRC = TWAIN_RGBResponseSet (pOrigin, pDest, pData);
547 DSM_twCC = TWCC_BADPROTOCOL;
548 WARN("unrecognized operation triplet\n");
555 DSM_twCC = TWCC_BADPROTOCOL;
556 WARN("unrecognized operation triplet\n");
561 TW_UINT16 TWAIN_AudioGroupHandler (
562 pTW_IDENTITY pOrigin,
568 TW_UINT16 twRC = TWRC_FAILURE;
572 case DAT_AUDIOFILEXFER:
574 twRC = TWAIN_AudioFileXferGet (pOrigin, pDest, pData);
579 twRC = TWAIN_AudioInfoGet (pOrigin, pDest, pData);
582 case DAT_AUDIONATIVEXFER:
584 twRC = TWAIN_AudioNativeXferGet (pOrigin, pDest, pData);
588 DSM_twCC = TWCC_BADPROTOCOL;
596 /* Main entry point for the TWAIN library */
598 DSM_Entry (pTW_IDENTITY pOrigin,
605 TW_UINT16 twRC = TWRC_SUCCESS; /* Return Code */
607 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG, DAT, MSG);
612 twRC = TWAIN_ControlGroupHandler (pOrigin,pDest,DAT,MSG,pData);
615 twRC = TWAIN_ImageGroupHandler (pOrigin,pDest,DAT,MSG,pData);
618 twRC = TWAIN_AudioGroupHandler (pOrigin,pDest,DAT,MSG,pData);
621 DSM_twCC = TWCC_BADPROTOCOL;
628 /* A helper function that looks up a destination identity in the active
630 activeDS *TWAIN_LookupSource (pTW_IDENTITY pDest)
634 for (pSource = activeSources; pSource; pSource = pSource->next)
635 if (pSource->identity.Id == pDest->Id)