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 extern HINSTANCE DSM_hinstance
;
36 BOOL WINAPI
DllMain (HINSTANCE hinstance
, DWORD reason
, LPVOID reserved
)
38 TRACE("%p,%x,%p\n", hinstance
, reason
, reserved
);
42 case DLL_PROCESS_ATTACH
:
43 DisableThreadLibraryCalls(hinstance
);
44 DSM_hinstance
= hinstance
;
46 case DLL_PROCESS_DETACH
:
52 /* A helper function that looks up a destination identity in the active
54 static activeDS
*TWAIN_LookupSource (const TW_IDENTITY
*pDest
)
58 for (pSource
= activeSources
; pSource
; pSource
= pSource
->next
)
59 if (pSource
->identity
.Id
== pDest
->Id
)
64 static TW_UINT16
TWAIN_SourceManagerHandler (
70 TW_UINT16 twRC
= TWRC_SUCCESS
;
78 twRC
= TWAIN_CloseDS (pOrigin
, pData
);
82 twRC
= TWAIN_IdentityGetDefault (pOrigin
, pData
);
86 twRC
= TWAIN_IdentityGetFirst (pOrigin
, pData
);
90 twRC
= TWAIN_IdentityGetNext (pOrigin
, pData
);
94 twRC
= TWAIN_OpenDS (pOrigin
, pData
);
98 twRC
= TWAIN_UserSelect (pOrigin
, pData
);
102 /* Unrecognized operation triplet */
104 DSM_twCC
= TWCC_BADPROTOCOL
;
105 WARN("unrecognized operation triplet\n");
114 twRC
= TWAIN_CloseDSM (pOrigin
, pData
);
118 twRC
= TWAIN_OpenDSM (pOrigin
, pData
);
122 /* Unrecognized operation triplet */
124 DSM_twCC
= TWCC_BADPROTOCOL
;
125 WARN("unrecognized operation triplet\n");
130 if (MSG
== MSG_GET
) {
131 twRC
= TWAIN_GetDSMStatus (pOrigin
, pData
);
134 DSM_twCC
= TWCC_BADPROTOCOL
;
135 WARN("unrecognized operation triplet\n");
141 DSM_twCC
= TWCC_BADPROTOCOL
;
142 WARN("unrecognized operation triplet\n");
150 /* Main entry point for the TWAIN library */
152 DSM_Entry (pTW_IDENTITY pOrigin
,
159 TW_UINT16 twRC
= TWRC_SUCCESS
; /* Return Code */
161 TRACE("(DG=%d DAT=%d MSG=%d)\n", DG
, DAT
, MSG
);
163 if (DG
== DG_CONTROL
&& DAT
== DAT_NULL
)
165 activeDS
*pSource
= TWAIN_LookupSource (pOrigin
);
168 ERR("No source associated with pSource %p\n", pDest
);
169 DSM_twCC
= TWCC_BADPROTOCOL
;
173 return TWAIN_ControlNull (pOrigin
, pDest
, pSource
, MSG
, pData
);
178 activeDS
*pSource
= TWAIN_LookupSource (pDest
);
179 /* This operation's destination is a source */
182 ERR("No source associated with pDest %p\n", pDest
);
183 DSM_twCC
= TWCC_BADDEST
;
187 if (DG
== DG_CONTROL
&& DAT
== DAT_EVENT
&& MSG
== MSG_PROCESSEVENT
)
189 twRC
= TWAIN_ProcessEvent(pOrigin
, pSource
, pData
);
190 if (twRC
== TWRC_DSEVENT
)
194 if (DG
== DG_CONTROL
&& DAT
== DAT_USERINTERFACE
&&
195 (MSG
== MSG_ENABLEDS
|| MSG
== MSG_ENABLEDSUIONLY
) &&
198 pSource
->ui_window
= ((TW_USERINTERFACE
*)pData
)->hParent
;
201 DSM_twCC
= TWCC_SUCCESS
;
202 TRACE("Forwarding %d/%d/%d/%p to DS.\n", DG
, DAT
, MSG
, pData
);
203 twRC
= pSource
->dsEntry(pOrigin
, DG
, DAT
, MSG
, pData
);
204 TRACE("return value is %d\n", twRC
);
210 twRC
= TWAIN_SourceManagerHandler (pOrigin
, DAT
, MSG
, pData
);
213 FIXME("The DSM does not handle DG %d\n", DG
);
214 DSM_twCC
= TWCC_BADPROTOCOL
;