kernelbase: Let GetModuleBaseName succeed on 64bit modules in wow64.
[wine.git] / dlls / sane.ds / sane_main.c
blob8f07ce6d52aaad3787b59b9a4165dd2ba27112bd
1 /*
2 * SANE.DS functions
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "sane_i.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(twain);
29 struct tagActiveDS activeDS;
31 DSMENTRYPROC SANE_dsmentry;
32 HINSTANCE SANE_instance;
34 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
36 TRACE("%p,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
38 switch (fdwReason)
40 case DLL_PROCESS_ATTACH: {
41 SANE_instance = hinstDLL;
42 DisableThreadLibraryCalls(hinstDLL);
43 if (__wine_init_unix_call()) return FALSE;
44 SANE_CALL( process_attach, NULL );
45 break;
47 case DLL_PROCESS_DETACH:
48 if (lpvReserved) break;
49 SANE_CALL( process_detach, NULL );
50 break;
53 return TRUE;
56 static TW_UINT16 SANE_OpenDS( pTW_IDENTITY pOrigin, pTW_IDENTITY self)
58 if (SANE_dsmentry == NULL)
60 HMODULE moddsm = GetModuleHandleW(L"twain_32");
62 if (moddsm)
63 SANE_dsmentry = (void*)GetProcAddress(moddsm, "DSM_Entry");
65 if (!SANE_dsmentry)
67 ERR("can't find DSM entry point\n");
68 return TWRC_FAILURE;
72 if (SANE_CALL( open_ds, self )) return TWRC_FAILURE;
74 activeDS.twCC = SANE_SaneSetDefaults();
75 if (activeDS.twCC == TWCC_SUCCESS)
77 activeDS.currentState = 4;
78 activeDS.identity.Id = self->Id;
79 activeDS.appIdentity = *pOrigin;
80 return TWRC_SUCCESS;
82 SANE_CALL( close_ds, NULL );
83 return TWRC_FAILURE;
86 static TW_UINT16 SANE_SetEntryPoint (pTW_IDENTITY pOrigin, TW_MEMREF pData);
88 static TW_UINT16 SANE_SourceControlHandler (
89 pTW_IDENTITY pOrigin,
90 TW_UINT16 DAT,
91 TW_UINT16 MSG,
92 TW_MEMREF pData)
94 TW_UINT16 twRC = TWRC_SUCCESS;
96 switch (DAT)
98 case DAT_IDENTITY:
99 switch (MSG)
101 case MSG_CLOSEDS:
102 SANE_CALL( close_ds, NULL );
103 break;
104 case MSG_OPENDS:
105 twRC = SANE_OpenDS( pOrigin, (pTW_IDENTITY)pData);
106 break;
107 case MSG_GET:
109 if (SANE_CALL( get_identity, pData ))
111 activeDS.twCC = TWCC_CAPUNSUPPORTED;
112 twRC = TWRC_FAILURE;
114 break;
117 break;
118 case DAT_CAPABILITY:
119 switch (MSG)
121 case MSG_GET:
122 twRC = SANE_CapabilityGet (pOrigin, pData);
123 break;
124 case MSG_GETCURRENT:
125 twRC = SANE_CapabilityGetCurrent (pOrigin, pData);
126 break;
127 case MSG_GETDEFAULT:
128 twRC = SANE_CapabilityGetDefault (pOrigin, pData);
129 break;
130 case MSG_QUERYSUPPORT:
131 twRC = SANE_CapabilityQuerySupport (pOrigin, pData);
132 break;
133 case MSG_RESET:
134 twRC = SANE_CapabilityReset (pOrigin, pData);
135 break;
136 case MSG_SET:
137 twRC = SANE_CapabilitySet (pOrigin, pData);
138 break;
139 default:
140 twRC = TWRC_FAILURE;
141 activeDS.twCC = TWCC_CAPBADOPERATION;
142 FIXME("unrecognized operation triplet\n");
143 break;
145 break;
147 case DAT_ENTRYPOINT:
148 if (MSG == MSG_SET)
149 twRC = SANE_SetEntryPoint (pOrigin, pData);
150 else
152 twRC = TWRC_FAILURE;
153 activeDS.twCC = TWCC_CAPBADOPERATION;
154 FIXME("unrecognized operation triplet\n");
156 break;
158 case DAT_EVENT:
159 if (MSG == MSG_PROCESSEVENT)
160 twRC = SANE_ProcessEvent (pOrigin, pData);
161 else
163 activeDS.twCC = TWCC_CAPBADOPERATION;
164 twRC = TWRC_FAILURE;
166 break;
168 case DAT_PENDINGXFERS:
169 switch (MSG)
171 case MSG_ENDXFER:
172 twRC = SANE_PendingXfersEndXfer (pOrigin, pData);
173 break;
174 case MSG_GET:
175 twRC = SANE_PendingXfersGet (pOrigin, pData);
176 break;
177 case MSG_RESET:
178 twRC = SANE_PendingXfersReset (pOrigin, pData);
179 break;
180 default:
181 activeDS.twCC = TWCC_CAPBADOPERATION;
182 twRC = TWRC_FAILURE;
184 break;
186 case DAT_SETUPMEMXFER:
187 if (MSG == MSG_GET)
188 twRC = SANE_SetupMemXferGet (pOrigin, pData);
189 else
191 activeDS.twCC = TWCC_CAPBADOPERATION;
192 twRC = TWRC_FAILURE;
194 break;
196 case DAT_STATUS:
197 if (MSG == MSG_GET)
198 twRC = SANE_GetDSStatus (pOrigin, pData);
199 else
201 activeDS.twCC = TWCC_CAPBADOPERATION;
202 twRC = TWRC_FAILURE;
204 break;
206 case DAT_USERINTERFACE:
207 switch (MSG)
209 case MSG_DISABLEDS:
210 twRC = SANE_DisableDSUserInterface (pOrigin, pData);
211 break;
212 case MSG_ENABLEDS:
213 twRC = SANE_EnableDSUserInterface (pOrigin, pData);
214 break;
215 case MSG_ENABLEDSUIONLY:
216 twRC = SANE_EnableDSUIOnly (pOrigin, pData);
217 break;
218 default:
219 activeDS.twCC = TWCC_CAPBADOPERATION;
220 twRC = TWRC_FAILURE;
221 break;
223 break;
225 case DAT_XFERGROUP:
226 switch (MSG)
228 case MSG_GET:
229 twRC = SANE_XferGroupGet (pOrigin, pData);
230 break;
231 case MSG_SET:
232 twRC = SANE_XferGroupSet (pOrigin, pData);
233 break;
234 default:
235 activeDS.twCC = TWCC_CAPBADOPERATION;
236 twRC = TWRC_FAILURE;
237 break;
239 break;
241 default:
242 WARN("code unsupported: %d\n", DAT);
243 activeDS.twCC = TWCC_CAPUNSUPPORTED;
244 twRC = TWRC_FAILURE;
245 break;
248 return twRC;
252 static TW_UINT16 SANE_ImageGroupHandler (
253 pTW_IDENTITY pOrigin,
254 TW_UINT16 DAT,
255 TW_UINT16 MSG,
256 TW_MEMREF pData)
258 TW_UINT16 twRC = TWRC_SUCCESS;
260 switch (DAT)
262 case DAT_IMAGEINFO:
263 if (MSG == MSG_GET)
264 twRC = SANE_ImageInfoGet (pOrigin, pData);
265 else
267 activeDS.twCC = TWCC_CAPBADOPERATION;
268 twRC = TWRC_FAILURE;
270 break;
272 case DAT_IMAGELAYOUT:
273 switch (MSG)
275 case MSG_GET:
276 twRC = SANE_ImageLayoutGet (pOrigin, pData);
277 break;
278 case MSG_GETDEFAULT:
279 twRC = SANE_ImageLayoutGetDefault (pOrigin, pData);
280 break;
281 case MSG_RESET:
282 twRC = SANE_ImageLayoutReset (pOrigin, pData);
283 break;
284 case MSG_SET:
285 twRC = SANE_ImageLayoutSet (pOrigin, pData);
286 break;
287 default:
288 twRC = TWRC_FAILURE;
289 activeDS.twCC = TWCC_CAPBADOPERATION;
290 ERR("unrecognized operation triplet\n");
291 break;
293 break;
295 case DAT_IMAGEMEMXFER:
296 if (MSG == MSG_GET)
297 twRC = SANE_ImageMemXferGet (pOrigin, pData);
298 else
300 activeDS.twCC = TWCC_CAPBADOPERATION;
301 twRC = TWRC_FAILURE;
303 break;
305 case DAT_IMAGENATIVEXFER:
306 if (MSG == MSG_GET)
307 twRC = SANE_ImageNativeXferGet (pOrigin, pData);
308 else
310 activeDS.twCC = TWCC_CAPBADOPERATION;
311 twRC = TWRC_FAILURE;
313 break;
315 default:
316 twRC = TWRC_FAILURE;
317 activeDS.twCC = TWCC_CAPUNSUPPORTED;
318 WARN("unsupported DG type %d\n", DAT);
319 break;
321 return twRC;
324 /* Main entry point for the TWAIN library */
325 TW_UINT16 WINAPI
326 DS_Entry ( pTW_IDENTITY pOrigin,
327 TW_UINT32 DG,
328 TW_UINT16 DAT,
329 TW_UINT16 MSG,
330 TW_MEMREF pData)
332 TW_UINT16 twRC = TWRC_SUCCESS; /* Return Code */
334 TRACE("(DG=%ld DAT=%d MSG=%d)\n", DG, DAT, MSG);
336 switch (DG)
338 case DG_CONTROL:
339 twRC = SANE_SourceControlHandler (pOrigin,DAT,MSG,pData);
340 break;
341 case DG_IMAGE:
342 twRC = SANE_ImageGroupHandler (pOrigin,DAT,MSG,pData);
343 break;
344 case DG_AUDIO:
345 WARN("Audio group of controls not implemented yet.\n");
346 twRC = TWRC_FAILURE;
347 activeDS.twCC = TWCC_CAPUNSUPPORTED;
348 break;
349 default:
350 activeDS.twCC = TWCC_BADPROTOCOL;
351 twRC = TWRC_FAILURE;
354 return twRC;
357 void SANE_Notify (TW_UINT16 message)
359 SANE_dsmentry (&activeDS.identity, &activeDS.appIdentity, DG_CONTROL, DAT_NULL, message, NULL);
362 /* DG_CONTROL/DAT_ENTRYPOINT/MSG_SET */
363 TW_UINT16 SANE_SetEntryPoint (pTW_IDENTITY pOrigin, TW_MEMREF pData)
365 TW_ENTRYPOINT *entry = (TW_ENTRYPOINT*)pData;
367 SANE_dsmentry = entry->DSM_Entry;
369 return TWRC_SUCCESS;