4 * Copyright 2000 Shi Quan He <shiquan@cyberdude.com>
5 * Copyright 2006 Marcus Meissner
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(twain);
34 /* A helper function that looks up a destination identity in the active
36 static activeDS *TWAIN_LookupSource (const TW_IDENTITY *pDest)
40 for (pSource = activeSources; pSource; pSource = pSource->next)
41 if (pSource->identity.Id == pDest->Id)
46 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
48 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
52 case DLL_PROCESS_ATTACH:
53 DisableThreadLibraryCalls(hinstDLL);
57 case DLL_PROCESS_DETACH:
65 static TW_UINT16 TWAIN_SourceManagerHandler (
71 TW_UINT16 twRC = TWRC_SUCCESS;
79 twRC = TWAIN_CloseDS (pOrigin, pData);
83 twRC = TWAIN_IdentityGetDefault (pOrigin, pData);
87 twRC = TWAIN_IdentityGetFirst (pOrigin, pData);
91 twRC = TWAIN_IdentityGetNext (pOrigin, pData);
95 twRC = TWAIN_OpenDS (pOrigin, pData);
99 twRC = TWAIN_UserSelect (pOrigin, pData);
103 /* Unrecognized operation triplet */
105 DSM_twCC = TWCC_BADPROTOCOL;
106 WARN("unrecognized operation triplet\n");
115 twRC = TWAIN_CloseDSM (pOrigin, pData);
119 twRC = TWAIN_OpenDSM (pOrigin, pData);
123 /* Unrecognized operation triplet */
125 DSM_twCC = TWCC_BADPROTOCOL;
126 WARN("unrecognized operation triplet\n");
131 if (MSG == MSG_GET) {
132 twRC = TWAIN_GetDSMStatus (pOrigin, pData);
135 DSM_twCC = TWCC_BADPROTOCOL;
136 WARN("unrecognized operation triplet\n");
142 DSM_twCC = TWCC_BADPROTOCOL;
143 WARN("unrecognized operation triplet\n");
151 /* Main entry point for the TWAIN library */
153 DSM_Entry (pTW_IDENTITY pOrigin,
160 TW_UINT16 twRC = TWRC_SUCCESS; /* Return Code */
162 TRACE("(DG=%d DAT=%d MSG=%d)\n", DG, DAT, MSG);
166 activeDS *pSource = TWAIN_LookupSource (pDest);
167 /* This operation's destination is a source */
170 ERR("No source associated with pDest %p\n", pDest);
171 DSM_twCC = TWCC_BADDEST;
174 DSM_twCC = TWCC_SUCCESS;
175 TRACE("Forwarding %d/%d/%d/%p to DS.\n", DG, DAT, MSG, pData);
176 twRC = pSource->dsEntry(pOrigin, DG, DAT, MSG, pData);
177 TRACE("return value is %d\n", twRC);
183 twRC = TWAIN_SourceManagerHandler (pOrigin, DAT, MSG, pData);
186 FIXME("The DSM does not handle DG %d\n", DG);
187 DSM_twCC = TWCC_BADPROTOCOL;