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
;
33 unixlib_handle_t sane_handle
= 0;
35 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
37 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
41 case DLL_PROCESS_ATTACH
: {
42 SANE_instance
= hinstDLL
;
43 DisableThreadLibraryCalls(hinstDLL
);
44 if (NtQueryVirtualMemory( GetCurrentProcess(), hinstDLL
, MemoryWineUnixFuncs
,
45 &sane_handle
, sizeof(sane_handle
), NULL
)) return FALSE
;
46 SANE_CALL( process_attach
, NULL
);
49 case DLL_PROCESS_DETACH
:
50 if (lpvReserved
) break;
51 SANE_CALL( process_detach
, NULL
);
58 static TW_UINT16
SANE_OpenDS( pTW_IDENTITY pOrigin
, pTW_IDENTITY self
)
60 if (SANE_dsmentry
== NULL
)
62 HMODULE moddsm
= GetModuleHandleW(L
"twain_32");
65 SANE_dsmentry
= (void*)GetProcAddress(moddsm
, "DSM_Entry");
69 ERR("can't find DSM entry point\n");
74 if (SANE_CALL( open_ds
, self
)) return TWRC_FAILURE
;
76 activeDS
.twCC
= SANE_SaneSetDefaults();
77 if (activeDS
.twCC
== TWCC_SUCCESS
)
79 activeDS
.currentState
= 4;
80 activeDS
.identity
.Id
= self
->Id
;
81 activeDS
.appIdentity
= *pOrigin
;
84 SANE_CALL( close_ds
, NULL
);
88 static TW_UINT16
SANE_SetEntryPoint (pTW_IDENTITY pOrigin
, TW_MEMREF pData
);
90 static TW_UINT16
SANE_SourceControlHandler (
96 TW_UINT16 twRC
= TWRC_SUCCESS
;
104 SANE_CALL( close_ds
, NULL
);
107 twRC
= SANE_OpenDS( pOrigin
, (pTW_IDENTITY
)pData
);
111 if (SANE_CALL( get_identity
, pData
))
113 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
124 twRC
= SANE_CapabilityGet (pOrigin
, pData
);
127 twRC
= SANE_CapabilityGetCurrent (pOrigin
, pData
);
130 twRC
= SANE_CapabilityGetDefault (pOrigin
, pData
);
132 case MSG_QUERYSUPPORT
:
133 twRC
= SANE_CapabilityQuerySupport (pOrigin
, pData
);
136 twRC
= SANE_CapabilityReset (pOrigin
, pData
);
139 twRC
= SANE_CapabilitySet (pOrigin
, pData
);
143 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
144 FIXME("unrecognized operation triplet\n");
151 twRC
= SANE_SetEntryPoint (pOrigin
, pData
);
155 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
156 FIXME("unrecognized operation triplet\n");
161 if (MSG
== MSG_PROCESSEVENT
)
162 twRC
= SANE_ProcessEvent (pOrigin
, pData
);
165 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
170 case DAT_PENDINGXFERS
:
174 twRC
= SANE_PendingXfersEndXfer (pOrigin
, pData
);
177 twRC
= SANE_PendingXfersGet (pOrigin
, pData
);
180 twRC
= SANE_PendingXfersReset (pOrigin
, pData
);
183 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
188 case DAT_SETUPMEMXFER
:
190 twRC
= SANE_SetupMemXferGet (pOrigin
, pData
);
193 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
200 twRC
= SANE_GetDSStatus (pOrigin
, pData
);
203 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
208 case DAT_USERINTERFACE
:
212 twRC
= SANE_DisableDSUserInterface (pOrigin
, pData
);
215 twRC
= SANE_EnableDSUserInterface (pOrigin
, pData
);
217 case MSG_ENABLEDSUIONLY
:
218 twRC
= SANE_EnableDSUIOnly (pOrigin
, pData
);
221 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
231 twRC
= SANE_XferGroupGet (pOrigin
, pData
);
234 twRC
= SANE_XferGroupSet (pOrigin
, pData
);
237 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
244 WARN("code unsupported: %d\n", DAT
);
245 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
254 static TW_UINT16
SANE_ImageGroupHandler (
255 pTW_IDENTITY pOrigin
,
260 TW_UINT16 twRC
= TWRC_SUCCESS
;
266 twRC
= SANE_ImageInfoGet (pOrigin
, pData
);
269 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
274 case DAT_IMAGELAYOUT
:
278 twRC
= SANE_ImageLayoutGet (pOrigin
, pData
);
281 twRC
= SANE_ImageLayoutGetDefault (pOrigin
, pData
);
284 twRC
= SANE_ImageLayoutReset (pOrigin
, pData
);
287 twRC
= SANE_ImageLayoutSet (pOrigin
, pData
);
291 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
292 ERR("unrecognized operation triplet\n");
297 case DAT_IMAGEMEMXFER
:
299 twRC
= SANE_ImageMemXferGet (pOrigin
, pData
);
302 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
307 case DAT_IMAGENATIVEXFER
:
309 twRC
= SANE_ImageNativeXferGet (pOrigin
, pData
);
312 activeDS
.twCC
= TWCC_CAPBADOPERATION
;
319 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
320 WARN("unsupported DG type %d\n", DAT
);
326 /* Main entry point for the TWAIN library */
328 DS_Entry ( pTW_IDENTITY pOrigin
,
334 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
336 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
341 twRC
= SANE_SourceControlHandler (pOrigin
,DAT
,MSG
,pData
);
344 twRC
= SANE_ImageGroupHandler (pOrigin
,DAT
,MSG
,pData
);
347 WARN("Audio group of controls not implemented yet.\n");
349 activeDS
.twCC
= TWCC_CAPUNSUPPORTED
;
352 activeDS
.twCC
= TWCC_BADPROTOCOL
;
359 void SANE_Notify (TW_UINT16 message
)
361 SANE_dsmentry (&activeDS
.identity
, &activeDS
.appIdentity
, DG_CONTROL
, DAT_NULL
, message
, NULL
);
364 /* DG_CONTROL/DAT_ENTRYPOINT/MSG_SET */
365 TW_UINT16
SANE_SetEntryPoint (pTW_IDENTITY pOrigin
, TW_MEMREF pData
)
367 TW_ENTRYPOINT
*entry
= (TW_ENTRYPOINT
*)pData
;
369 SANE_dsmentry
= entry
->DSM_Entry
;