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
);
42 DSM_instance
= hinstDLL
;
45 case DLL_PROCESS_DETACH
:
53 TW_UINT16
TWAIN_SourceManagerHandler (
59 TW_UINT16 twRC
= TWRC_SUCCESS
;
67 twRC
= TWAIN_CloseDS (pOrigin
, pData
);
71 twRC
= TWAIN_IdentityGetDefault (pOrigin
, pData
);
75 twRC
= TWAIN_IdentityGetFirst (pOrigin
, pData
);
79 twRC
= TWAIN_IdentityGetNext (pOrigin
, pData
);
83 twRC
= TWAIN_OpenDS (pOrigin
, pData
);
87 twRC
= TWAIN_UserSelect (pOrigin
, pData
);
91 /* Unrecognized operation triplet */
93 DSM_twCC
= TWCC_BADPROTOCOL
;
94 WARN("unrecognized operation triplet\n");
103 twRC
= TWAIN_CloseDSM (pOrigin
, pData
);
107 twRC
= TWAIN_OpenDSM (pOrigin
, pData
);
111 /* Unrecognized operation triplet */
113 DSM_twCC
= TWCC_BADPROTOCOL
;
114 WARN("unrecognized operation triplet\n");
121 twRC
= TWAIN_GetDSMStatus (pOrigin
, pData
);
126 DSM_twCC
= TWCC_BADPROTOCOL
;
127 WARN("unrecognized operation triplet\n");
133 DSM_twCC
= TWCC_BADPROTOCOL
;
134 WARN("unrecognized operation triplet\n");
141 TW_UINT16
TWAIN_SourceControlHandler (
142 pTW_IDENTITY pOrigin
,
148 TW_UINT16 twRC
= TWRC_SUCCESS
;
156 twRC
= TWAIN_CapabilityGet (pOrigin
, pDest
, pData
);
159 twRC
= TWAIN_CapabilityGetCurrent (pOrigin
, pDest
, pData
);
162 twRC
= TWAIN_CapabilityGetDefault (pOrigin
, pDest
, pData
);
164 case MSG_QUERYSUPPORT
:
165 twRC
= TWAIN_CapabilityQuerySupport (pOrigin
, pDest
, pData
);
168 twRC
= TWAIN_CapabilityReset (pOrigin
, pDest
, pData
);
171 twRC
= TWAIN_CapabilitySet (pOrigin
, pDest
, pData
);
175 WARN("unrecognized opertion triplet\n");
179 case DAT_CUSTOMDSDATA
:
183 twRC
= TWAIN_CustomDSDataGet (pOrigin
, pDest
, pData
);
186 twRC
= TWAIN_CustomDSDataSet (pOrigin
, pDest
, pData
);
196 /*case MSG_AUTOMATICCAPTUREDIRECTORY:
197 twRC = TWAIN_AutomaticCaptureDirectory
198 (pOrigin, pDest, pData);
200 case MSG_CHANGEDIRECTORY
:
201 twRC
= TWAIN_ChangeDirectory (pOrigin
, pDest
, pData
);
204 twRC = TWAIN_FileSystemCopy (pOrigin, pDest, pData);
206 case MSG_CREATEDIRECTORY
:
207 twRC
= TWAIN_CreateDirectory (pOrigin
, pDest
, pData
);
210 twRC
= TWAIN_FileSystemDelete (pOrigin
, pDest
, pData
);
212 case MSG_FORMATMEDIA
:
213 twRC
= TWAIN_FormatMedia (pOrigin
, pDest
, pData
);
216 twRC
= TWAIN_FileSystemGetClose (pOrigin
, pDest
, pData
);
218 case MSG_GETFIRSTFILE
:
219 twRC
= TWAIN_FileSystemGetFirstFile
220 (pOrigin
, pDest
, pData
);
223 twRC
= TWAIN_FileSystemGetInfo (pOrigin
, pDest
, pData
);
225 case MSG_GETNEXTFILE
:
226 twRC
= TWAIN_FileSystemGetNextFile
227 (pOrigin
, pDest
, pData
);
230 twRC
= TWAIN_FileSystemRename (pOrigin
, pDest
, pData
);
239 if (MSG
== MSG_PROCESSEVENT
)
240 twRC
= TWAIN_ProcessEvent (pOrigin
, pDest
, pData
);
246 if (MSG
== MSG_PASSTHRU
)
247 twRC
= TWAIN_PassThrough (pOrigin
, pDest
, pData
);
252 case DAT_PENDINGXFERS
:
256 twRC
= TWAIN_PendingXfersEndXfer (pOrigin
, pDest
, pData
);
259 twRC
= TWAIN_PendingXfersGet (pOrigin
, pDest
, pData
);
262 twRC
= TWAIN_PendingXfersReset (pOrigin
, pDest
, pData
);
264 /*case MSG_STOPFEEDER:
265 twRC = TWAIN_PendingXfersStopFeeder
266 (pOrigin, pDest, pData);
273 case DAT_SETUPFILEXFER
:
277 twRC
= TWAIN_SetupFileXferGet (pOrigin
, pDest
, pData
);
280 twRC
= TWAIN_SetupFileXferGetDefault
281 (pOrigin
, pDest
, pData
);
284 twRC
= TWAIN_SetupFileXferReset (pOrigin
, pDest
, pData
);
287 twRC
= TWAIN_SetupFileXferSet (pOrigin
, pDest
, pData
);
295 /*case DAT_SETUPFILEXFER2:
299 twRC = TWAIN_SetupFileXfer2Get (pOrigin, pDest, pData);
302 twRC = TWAIN_SetupFileXfer2GetDefault
303 (pOrigin, pDest, pData);
306 twRC = TWAIN_SetupFileXfer2Reset (pOrigin, pDest, pData);
309 twRC = TWAIN_SetupFileXfer2Set (pOrigin, pDest, pData);
313 case DAT_SETUPMEMXFER
:
315 twRC
= TWAIN_SetupMemXferGet (pOrigin
, pDest
, pData
);
322 twRC
= TWAIN_GetDSStatus (pOrigin
, pDest
, pData
);
327 case DAT_USERINTERFACE
:
331 twRC
= TWAIN_DisableDSUserInterface
332 (pOrigin
, pDest
, pData
);
335 twRC
= TWAIN_EnableDSUserInterface
336 (pOrigin
, pDest
, pData
);
338 case MSG_ENABLEDSUIONLY
:
339 twRC
= TWAIN_EnableDSUIOnly (pOrigin
, pDest
, pData
);
351 twRC
= TWAIN_XferGroupGet (pOrigin
, pDest
, pData
);
354 twRC
= TWAIN_XferGroupSet (pOrigin
, pDest
, pData
);
370 TW_UINT16
TWAIN_ControlGroupHandler (
371 pTW_IDENTITY pOrigin
,
377 TW_UINT16 twRC
= TWRC_SUCCESS
;
381 /* This operation's destination is a source */
382 twRC
= TWAIN_SourceControlHandler (pOrigin
, pDest
, DAT
, MSG
, pData
);
386 /* This operation's destination is the Source Manager */
387 twRC
= TWAIN_SourceManagerHandler (pOrigin
, DAT
, MSG
, pData
);
393 TW_UINT16
TWAIN_ImageGroupHandler (
394 pTW_IDENTITY pOrigin
,
400 TW_UINT16 twRC
= TWRC_SUCCESS
;
404 DSM_twCC
= TWCC_BADDEST
;
412 twRC
= TWAIN_CIEColorGet (pOrigin
, pDest
, pData
);
417 case DAT_EXTIMAGEINFO
:
419 twRC
= TWAIN_ExtImageInfoGet (pOrigin
, pDest
, pData
);
424 case DAT_GRAYRESPONSE
:
428 twRC
= TWAIN_GrayResponseReset (pOrigin
, pDest
, pData
);
431 twRC
= TWAIN_GrayResponseSet (pOrigin
, pDest
, pData
);
435 DSM_twCC
= TWCC_BADPROTOCOL
;
436 WARN("unrecognized operation triplet\n");
440 case DAT_IMAGEFILEXFER
:
442 twRC
= TWAIN_ImageFileXferGet (pOrigin
, pDest
, pData
);
449 twRC
= TWAIN_ImageInfoGet (pOrigin
, pDest
, pData
);
454 case DAT_IMAGELAYOUT
:
458 twRC
= TWAIN_ImageLayoutGet (pOrigin
, pDest
, pData
);
461 twRC
= TWAIN_ImageLayoutGetDefault (pOrigin
, pDest
, pData
);
464 twRC
= TWAIN_ImageLayoutReset (pOrigin
, pDest
, pData
);
467 twRC
= TWAIN_ImageLayoutSet (pOrigin
, pDest
, pData
);
471 DSM_twCC
= TWCC_BADPROTOCOL
;
472 WARN("unrecognized operation triplet\n");
477 case DAT_IMAGEMEMXFER
:
479 twRC
= TWAIN_ImageMemXferGet (pOrigin
, pDest
, pData
);
484 case DAT_IMAGENATIVEXFER
:
486 twRC
= TWAIN_ImageNativeXferGet (pOrigin
, pDest
, pData
);
491 case DAT_JPEGCOMPRESSION
:
495 twRC
= TWAIN_JPEGCompressionGet (pOrigin
, pDest
, pData
);
498 twRC
= TWAIN_JPEGCompressionGetDefault
499 (pOrigin
, pDest
, pData
);
502 twRC
= TWAIN_JPEGCompressionReset (pOrigin
, pDest
, pData
);
505 twRC
= TWAIN_JPEGCompressionSet (pOrigin
, pDest
, pData
);
509 DSM_twCC
= TWCC_BADPROTOCOL
;
510 WARN("unrecognized operation triplet\n");
519 twRC
= TWAIN_Palette8Get (pOrigin
, pDest
, pData
);
522 twRC
= TWAIN_Palette8GetDefault (pOrigin
, pDest
, pData
);
525 twRC
= TWAIN_Palette8Reset (pOrigin
, pDest
, pData
);
528 twRC
= TWAIN_Palette8Set (pOrigin
, pDest
, pData
);
532 DSM_twCC
= TWCC_BADPROTOCOL
;
533 WARN("unrecognized operation triplet\n");
537 case DAT_RGBRESPONSE
:
541 twRC
= TWAIN_RGBResponseReset (pOrigin
, pDest
, pData
);
544 twRC
= TWAIN_RGBResponseSet (pOrigin
, pDest
, pData
);
548 DSM_twCC
= TWCC_BADPROTOCOL
;
549 WARN("unrecognized operation triplet\n");
556 DSM_twCC
= TWCC_BADPROTOCOL
;
557 WARN("unrecognized operation triplet\n");
562 TW_UINT16
TWAIN_AudioGroupHandler (
563 pTW_IDENTITY pOrigin
,
569 TW_UINT16 twRC
= TWRC_FAILURE
;
573 case DAT_AUDIOFILEXFER
:
575 twRC
= TWAIN_AudioFileXferGet (pOrigin
, pDest
, pData
);
580 twRC
= TWAIN_AudioInfoGet (pOrigin
, pDest
, pData
);
583 case DAT_AUDIONATIVEXFER
:
585 twRC
= TWAIN_AudioNativeXferGet (pOrigin
, pDest
, pData
);
589 DSM_twCC
= TWCC_BADPROTOCOL
;
597 /* Main entry point for the TWAIN library */
599 DSM_Entry (pTW_IDENTITY pOrigin
,
606 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
608 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
613 twRC
= TWAIN_ControlGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
616 twRC
= TWAIN_ImageGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
619 twRC
= TWAIN_AudioGroupHandler (pOrigin
,pDest
,DAT
,MSG
,pData
);
622 DSM_twCC
= TWCC_BADPROTOCOL
;
629 /* A helper function that looks up a destination identity in the active
631 activeDS
*TWAIN_LookupSource (pTW_IDENTITY pDest
)
635 for (pSource
= activeSources
; pSource
; pSource
= pSource
->next
)
636 if (pSource
->identity
.Id
== pDest
->Id
)