ReactOS  0.4.13-dev-92-gf251225
dsm_ctrl.c File Reference
#include "config.h"
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "twain.h"
#include "twain_i.h"
#include "resource.h"
#include "wine/debug.h"
Include dependency graph for dsm_ctrl.c:

Go to the source code of this file.

Classes

struct  all_devices
 
struct  userselect_data
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (twain)
 
static void twain_add_onedriver (const char *dsname)
 
static void twain_autodetect (void)
 
TW_UINT16 TWAIN_ControlNull (pTW_IDENTITY pOrigin, pTW_IDENTITY pDest, activeDS *pSource, TW_UINT16 MSG, TW_MEMREF pData)
 
TW_UINT16 TWAIN_ProcessEvent (pTW_IDENTITY pOrigin, activeDS *pSource, TW_MEMREF pData)
 
TW_UINT16 TWAIN_CloseDS (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
TW_UINT16 TWAIN_IdentityGetDefault (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
TW_UINT16 TWAIN_IdentityGetFirst (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
TW_UINT16 TWAIN_IdentityGetNext (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
TW_UINT16 TWAIN_OpenDS (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
static INT_PTR CALLBACK userselect_dlgproc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 
TW_UINT16 TWAIN_UserSelect (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
TW_UINT16 TWAIN_CloseDSM (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
TW_UINT16 TWAIN_OpenDSM (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 
TW_UINT16 TWAIN_GetDSMStatus (pTW_IDENTITY pOrigin, TW_MEMREF pData)
 

Variables

static TW_UINT16 DSM_initialized
 
static TW_UINT32 DSM_sourceId
 
static TW_UINT16 DSM_currentDevice
 
static HWND DSM_parent
 
static UINT event_message
 
static int nrdevices = 0
 
static struct all_devicesdevices = NULL
 
static BOOL detectionrun = FALSE
 

Function Documentation

◆ twain_add_onedriver()

static void twain_add_onedriver ( const char dsname)
static

Definition at line 53 of file dsm_ctrl.c.

53  {
54  HMODULE hmod;
55  DSENTRYPROC dsEntry;
56  TW_IDENTITY fakeOrigin;
57  TW_IDENTITY sourceId;
58  TW_UINT16 ret;
59 
60  hmod = LoadLibraryA(dsname);
61  if (!hmod) {
62  ERR("Failed to load TWAIN Source %s\n", dsname);
63  return;
64  }
65  dsEntry = (DSENTRYPROC)GetProcAddress(hmod, "DS_Entry");
66  if (!dsEntry) {
67  ERR("Failed to find DS_Entry() in TWAIN DS %s\n", dsname);
68  return;
69  }
70  /* Loop to do multiple detects, mostly for sane.ds and gphoto2.ds */
71  do {
72  int i;
73 
74  sourceId.Id = DSM_sourceId;
77  ret = dsEntry (&fakeOrigin, DG_CONTROL, DAT_IDENTITY, MSG_GET, &sourceId);
78  if (ret != TWRC_SUCCESS) {
79  ERR("Source->(DG_CONTROL,DAT_IDENTITY,MSG_GET) failed!\n");
80  break;
81  }
82  TRACE("Manufacturer: %s\n", debugstr_a(sourceId.Manufacturer));
83  TRACE("ProductFamily: %s\n", debugstr_a(sourceId.ProductFamily));
84  TRACE("ProductName: %s\n", debugstr_a(sourceId.ProductName));
85 
86  for (i=0;i<nrdevices;i++) {
87  if (!strcmp(sourceId.ProductName,devices[i].identity.ProductName))
88  break;
89  }
90  if (i < nrdevices)
91  break;
92  if (nrdevices)
93  devices = HeapReAlloc(GetProcessHeap(), 0, devices, sizeof(devices[0])*(nrdevices+1));
94  else
95  devices = HeapAlloc(GetProcessHeap(), 0, sizeof(devices[0]));
96  if ((devices[nrdevices].modname = HeapAlloc(GetProcessHeap(), 0, strlen(dsname) + 1)))
97  lstrcpyA(devices[nrdevices].modname, dsname);
98  devices[nrdevices].identity = sourceId;
99  nrdevices++;
100  DSM_sourceId++;
101  } while (1);
102  FreeLibrary (hmod);
103 }
static TW_UINT32 DSM_sourceId
Definition: dsm_ctrl.c:39
#define TWON_PROTOCOLMAJOR
Definition: twain.h:70
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TWRC_SUCCESS
Definition: twain.h:1664
unsigned short TW_UINT16
Definition: twain.h:119
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static int nrdevices
Definition: dsm_ctrl.c:49
TW_UINT16 ProtocolMinor
Definition: twain.h:260
#define TRACE(s)
Definition: solgame.cpp:4
#define FreeLibrary(x)
Definition: compat.h:405
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define debugstr_a
Definition: kernel32.h:31
TW_UINT16 ProtocolMajor
Definition: twain.h:259
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
static struct all_devices * devices
Definition: dsm_ctrl.c:50
TW_STR32 ProductName
Definition: twain.h:264
int ret
#define TWON_PROTOCOLMINOR
Definition: twain.h:69
#define DG_CONTROL
Definition: twain.h:1311
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
#define ERR(fmt,...)
Definition: debug.h:109
#define HeapReAlloc
Definition: compat.h:393
TW_UINT32 Id
Definition: twain.h:257
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define GetProcAddress(x, y)
Definition: compat.h:410
#define MSG_GET
Definition: twain.h:1385
TW_STR32 Manufacturer
Definition: twain.h:262
#define DAT_IDENTITY
Definition: twain.h:1337
TW_STR32 ProductFamily
Definition: twain.h:263

Referenced by twain_autodetect().

◆ twain_autodetect()

static void twain_autodetect ( void  )
static

Definition at line 108 of file dsm_ctrl.c.

108  {
109  if (detectionrun) return;
110  detectionrun = TRUE;
111 
112  twain_add_onedriver("sane.ds");
113  twain_add_onedriver("gphoto2.ds");
114 #if 0
115  twain_add_onedriver("c:\\windows\\Twain_32\\Largan\\sp503a.ds");
116  twain_add_onedriver("c:\\windows\\Twain_32\\vivicam10\\vivicam10.ds");
117  twain_add_onedriver("c:\\windows\\Twain_32\\ws30slim\\sp500a.ds");
118 #endif
119 }
#define TRUE
Definition: types.h:120
static void twain_add_onedriver(const char *dsname)
Definition: dsm_ctrl.c:53
static BOOL detectionrun
Definition: dsm_ctrl.c:105

Referenced by TWAIN_IdentityGetDefault(), TWAIN_IdentityGetFirst(), TWAIN_OpenDS(), and TWAIN_UserSelect().

◆ TWAIN_CloseDS()

TW_UINT16 TWAIN_CloseDS ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 202 of file dsm_ctrl.c.

203 {
204  TW_UINT16 twRC = TWRC_SUCCESS;
205  pTW_IDENTITY pIdentity = (pTW_IDENTITY) pData;
206  activeDS *currentDS = NULL, *prevDS = NULL;
207 
208  TRACE ("DG_CONTROL/DAT_IDENTITY/MSG_CLOSEDS\n");
209 
210  for (currentDS = activeSources; currentDS; currentDS = currentDS->next) {
211  if (currentDS->identity.Id == pIdentity->Id)
212  break;
213  prevDS = currentDS;
214  }
215  if (!currentDS) {
216  DSM_twCC = TWCC_NODS;
217  return TWRC_FAILURE;
218  }
219  twRC = currentDS->dsEntry (pOrigin, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, pData);
220  /* This causes crashes due to still open Windows, so leave out for now.
221  * FreeLibrary (currentDS->hmod);
222  */
223  if (prevDS)
224  prevDS->next = currentDS->next;
225  else
226  activeSources = currentDS->next;
227  HeapFree (GetProcessHeap(), 0, currentDS);
228  if (twRC == TWRC_SUCCESS)
229  DSM_twCC = TWCC_SUCCESS;
230  else /* FIXME: unclear how to get TWCC */
231  DSM_twCC = TWCC_SEQERROR;
232  return twRC;
233 }
struct tagActiveDS * next
Definition: twain_i.h:43
#define TWRC_SUCCESS
Definition: twain.h:1664
unsigned short TW_UINT16
Definition: twain.h:119
TW_IDENTITY identity
Definition: twain_i.h:44
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
#define MSG_CLOSEDS
Definition: twain.h:1410
DSENTRYPROC dsEntry
Definition: twain_i.h:46
#define DG_CONTROL
Definition: twain.h:1311
#define TWCC_SUCCESS
Definition: twain.h:1678
TW_UINT32 Id
Definition: twain.h:257
#define TWRC_FAILURE
Definition: twain.h:1665
#define TWCC_NODS
Definition: twain.h:1681
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
struct TW_IDENTITY * pTW_IDENTITY
Definition: twain.h:1762
#define HeapFree(x, y, z)
Definition: compat.h:394
#define TWCC_SEQERROR
Definition: twain.h:1687
#define DAT_IDENTITY
Definition: twain.h:1337

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_CloseDSM()

TW_UINT16 TWAIN_CloseDSM ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 457 of file dsm_ctrl.c.

458 {
459  activeDS *currentDS = activeSources, *nextDS;
460 
461  TRACE("DG_CONTROL/DAT_PARENT/MSG_CLOSEDSM\n");
462 
463  if (DSM_initialized)
464  {
466 
467  /* If there are data sources still open, close them now. */
468  while (currentDS != NULL)
469  {
470  nextDS = currentDS->next;
471  currentDS->dsEntry (pOrigin, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, pData);
472  HeapFree (GetProcessHeap(), 0, currentDS);
473  currentDS = nextDS;
474  }
475  activeSources = NULL;
476  DSM_parent = NULL;
477  DSM_twCC = TWCC_SUCCESS;
478  return TWRC_SUCCESS;
479  } else {
480  DSM_twCC = TWCC_SEQERROR;
481  return TWRC_FAILURE;
482  }
483 }
struct tagActiveDS * next
Definition: twain_i.h:43
#define TWRC_SUCCESS
Definition: twain.h:1664
smooth NULL
Definition: ftsmooth.c:416
static HWND DSM_parent
Definition: dsm_ctrl.c:41
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
#define MSG_CLOSEDS
Definition: twain.h:1410
DSENTRYPROC dsEntry
Definition: twain_i.h:46
#define DG_CONTROL
Definition: twain.h:1311
#define TWCC_SUCCESS
Definition: twain.h:1678
static TW_UINT16 DSM_initialized
Definition: dsm_ctrl.c:38
#define TWRC_FAILURE
Definition: twain.h:1665
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
#define HeapFree(x, y, z)
Definition: compat.h:394
#define TWCC_SEQERROR
Definition: twain.h:1687
#define DAT_IDENTITY
Definition: twain.h:1337

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_ControlNull()

TW_UINT16 TWAIN_ControlNull ( pTW_IDENTITY  pOrigin,
pTW_IDENTITY  pDest,
activeDS pSource,
TW_UINT16  MSG,
TW_MEMREF  pData 
)

Definition at line 122 of file dsm_ctrl.c.

123 {
124  struct pending_message *message;
125 
126  TRACE ("DG_CONTROL/DAT_NULL MSG=%i\n", MSG);
127 
128  if (MSG != MSG_CLOSEDSREQ &&
129  MSG != MSG_DEVICEEVENT &&
130  MSG != MSG_XFERREADY)
131  {
132  DSM_twCC = TWCC_BADPROTOCOL;
133  return TWRC_FAILURE;
134  }
135 
136  message = HeapAlloc(GetProcessHeap(), 0, sizeof(*message));
137  if (!message)
138  {
139  DSM_twCC = TWCC_LOWMEMORY;
140  return TWRC_FAILURE;
141  }
142 
143  message->msg = MSG;
144  list_add_tail(&pSource->pending_messages, &message->entry);
145 
146  /* Delphi twain only sends us messages from one window, and it
147  doesn't even give us the real handle to that window. Other
148  applications might decide to forward messages sent to DSM_parent
149  or to the one supplied to ENABLEDS. So let's try very hard to
150  find a window that will work. */
151  if (DSM_parent)
153  if (pSource->ui_window && pSource->ui_window != DSM_parent)
154  PostMessageW(pSource->ui_window, event_message, 0, 0);
155  if (pSource->event_window && pSource->event_window != pSource->ui_window &&
156  pSource->event_window != DSM_parent)
157  PostMessageW(pSource->event_window, event_message, 0, 0);
158  PostMessageW(0, event_message, 0, 0);
159 
160  return TWRC_SUCCESS;
161 }
HWND event_window
Definition: twain_i.h:49
Definition: tftpd.h:59
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define TWCC_LOWMEMORY
Definition: twain.h:1680
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
#define TWRC_SUCCESS
Definition: twain.h:1664
#define MSG_XFERREADY
Definition: twain.h:1395
static UINT event_message
Definition: dsm_ctrl.c:42
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
HWND ui_window
Definition: twain_i.h:48
#define MSG_CLOSEDSREQ
Definition: twain.h:1396
static HWND DSM_parent
Definition: dsm_ctrl.c:41
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define MSG_DEVICEEVENT
Definition: twain.h:1399
#define MSG
Definition: Mailslot.c:11
#define TWCC_BADPROTOCOL
Definition: twain.h:1685
struct list pending_messages
Definition: twain_i.h:47
#define TWRC_FAILURE
Definition: twain.h:1665
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)

Referenced by DSM_Entry().

◆ TWAIN_GetDSMStatus()

TW_UINT16 TWAIN_GetDSMStatus ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 507 of file dsm_ctrl.c.

508 {
509  pTW_STATUS pSourceStatus = (pTW_STATUS) pData;
510 
511  TRACE ("DG_CONTROL/DAT_STATUS/MSG_GET\n");
512 
513  pSourceStatus->ConditionCode = DSM_twCC;
514  DSM_twCC = TWCC_SUCCESS; /* clear the condition code */
515  return TWRC_SUCCESS;
516 }
#define TWRC_SUCCESS
Definition: twain.h:1664
#define TRACE(s)
Definition: solgame.cpp:4
struct TW_STATUS * pTW_STATUS
#define TWCC_SUCCESS
Definition: twain.h:1678
TW_UINT16 ConditionCode
Definition: twain.h:352
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_IdentityGetDefault()

TW_UINT16 TWAIN_IdentityGetDefault ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 236 of file dsm_ctrl.c.

237 {
238  pTW_IDENTITY pSourceIdentity = (pTW_IDENTITY) pData;
239 
240  TRACE("DG_CONTROL/DAT_IDENTITY/MSG_GETDEFAULT\n");
241  DSM_twCC = TWCC_NODS;
243  if (!nrdevices)
244  return TWRC_FAILURE;
245  *pSourceIdentity = devices[0].identity;
246  DSM_twCC = TWCC_SUCCESS;
247  return TWRC_SUCCESS;
248 }
static void twain_autodetect(void)
Definition: dsm_ctrl.c:108
#define TWRC_SUCCESS
Definition: twain.h:1664
static int nrdevices
Definition: dsm_ctrl.c:49
#define TRACE(s)
Definition: solgame.cpp:4
static struct all_devices * devices
Definition: dsm_ctrl.c:50
#define TWCC_SUCCESS
Definition: twain.h:1678
#define TWRC_FAILURE
Definition: twain.h:1665
#define TWCC_NODS
Definition: twain.h:1681
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
struct TW_IDENTITY * pTW_IDENTITY
Definition: twain.h:1762

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_IdentityGetFirst()

TW_UINT16 TWAIN_IdentityGetFirst ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 251 of file dsm_ctrl.c.

252 {
253  pTW_IDENTITY pSourceIdentity = (pTW_IDENTITY) pData;
254 
255  TRACE ("DG_CONTROL/DAT_IDENTITY/MSG_GETFIRST\n");
257  if (!nrdevices) {
258  TRACE ("no entries found.\n");
259  DSM_twCC = TWCC_NODS;
260  return TWRC_FAILURE;
261  }
262  DSM_currentDevice = 0;
263  *pSourceIdentity = devices[DSM_currentDevice++].identity;
264  return TWRC_SUCCESS;
265 }
static void twain_autodetect(void)
Definition: dsm_ctrl.c:108
#define TWRC_SUCCESS
Definition: twain.h:1664
static TW_UINT16 DSM_currentDevice
Definition: dsm_ctrl.c:40
static int nrdevices
Definition: dsm_ctrl.c:49
#define TRACE(s)
Definition: solgame.cpp:4
static struct all_devices * devices
Definition: dsm_ctrl.c:50
#define TWRC_FAILURE
Definition: twain.h:1665
#define TWCC_NODS
Definition: twain.h:1681
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
struct TW_IDENTITY * pTW_IDENTITY
Definition: twain.h:1762

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_IdentityGetNext()

TW_UINT16 TWAIN_IdentityGetNext ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 268 of file dsm_ctrl.c.

269 {
270  pTW_IDENTITY pSourceIdentity = (pTW_IDENTITY) pData;
271 
272  TRACE("DG_CONTROL/DAT_IDENTITY/MSG_GETNEXT\n");
273  if (!nrdevices || (DSM_currentDevice == nrdevices)) {
274  DSM_twCC = TWCC_SUCCESS;
275  return TWRC_ENDOFLIST;
276  }
277  *pSourceIdentity = devices[DSM_currentDevice++].identity;
278  return TWRC_SUCCESS;
279 }
#define TWRC_SUCCESS
Definition: twain.h:1664
static TW_UINT16 DSM_currentDevice
Definition: dsm_ctrl.c:40
static int nrdevices
Definition: dsm_ctrl.c:49
#define TRACE(s)
Definition: solgame.cpp:4
static struct all_devices * devices
Definition: dsm_ctrl.c:50
#define TWCC_SUCCESS
Definition: twain.h:1678
#define TWRC_ENDOFLIST
Definition: twain.h:1671
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
struct TW_IDENTITY * pTW_IDENTITY
Definition: twain.h:1762

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_OpenDS()

TW_UINT16 TWAIN_OpenDS ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 282 of file dsm_ctrl.c.

283 {
284  TW_UINT16 i = 0;
285  pTW_IDENTITY pIdentity = (pTW_IDENTITY) pData;
286  activeDS *newSource;
287  const char *modname = NULL;
288  HMODULE hmod;
289 
290  TRACE("DG_CONTROL/DAT_IDENTITY/MSG_OPENDS\n");
291  TRACE("pIdentity is %s\n", pIdentity->ProductName);
292  if (!DSM_initialized) {
293  FIXME("seq error\n");
294  DSM_twCC = TWCC_SEQERROR;
295  return TWRC_FAILURE;
296  }
298  if (!nrdevices) {
299  FIXME("no devs.\n");
300  DSM_twCC = TWCC_NODS;
301  return TWRC_FAILURE;
302  }
303 
304  if (pIdentity->ProductName[0] != '\0') {
305  /* Make sure the source to be opened exists in the device list */
306  for (i = 0; i<nrdevices; i++)
307  if (!strcmp (devices[i].identity.ProductName, pIdentity->ProductName))
308  break;
309  if (i == nrdevices)
310  i = 0;
311  } /* else use the first device */
312 
313  /* the source is found in the device list */
314  newSource = HeapAlloc (GetProcessHeap(), 0, sizeof (activeDS));
315  if (!newSource) {
316  DSM_twCC = TWCC_LOWMEMORY;
317  FIXME("Out of memory.\n");
318  return TWRC_FAILURE;
319  }
320  hmod = LoadLibraryA(devices[i].modname);
321  if (!hmod) {
322  ERR("Failed to load TWAIN Source %s\n", modname);
323  DSM_twCC = TWCC_OPERATIONERROR;
324  HeapFree(GetProcessHeap(), 0, newSource);
325  return TWRC_FAILURE;
326  }
327  newSource->hmod = hmod;
328  newSource->dsEntry = (DSENTRYPROC)GetProcAddress(hmod, "DS_Entry");
329  /* Assign id for the opened data source */
330  pIdentity->Id = DSM_sourceId ++;
331  if (TWRC_SUCCESS != newSource->dsEntry (pOrigin, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, pIdentity)) {
332  DSM_twCC = TWCC_OPERATIONERROR;
333  HeapFree(GetProcessHeap(), 0, newSource);
334  DSM_sourceId--;
335  return TWRC_FAILURE;
336  }
337  /* add the data source to an internal active source list */
338  newSource->next = activeSources;
339  newSource->identity.Id = pIdentity->Id;
340  strcpy (newSource->identity.ProductName, pIdentity->ProductName);
341  list_init(&newSource->pending_messages);
342  newSource->ui_window = NULL;
343  newSource->event_window = NULL;
344  activeSources = newSource;
345  DSM_twCC = TWCC_SUCCESS;
346  return TWRC_SUCCESS;
347 }
static TW_UINT32 DSM_sourceId
Definition: dsm_ctrl.c:39
HWND event_window
Definition: twain_i.h:49
struct tagActiveDS * next
Definition: twain_i.h:43
#define TWCC_LOWMEMORY
Definition: twain.h:1680
static void twain_autodetect(void)
Definition: dsm_ctrl.c:108
#define TWRC_SUCCESS
Definition: twain.h:1664
unsigned short TW_UINT16
Definition: twain.h:119
TW_IDENTITY identity
Definition: twain_i.h:44
#define TWCC_OPERATIONERROR
Definition: twain.h:1683
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HWND ui_window
Definition: twain_i.h:48
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define FIXME(fmt,...)
Definition: debug.h:110
static int nrdevices
Definition: dsm_ctrl.c:49
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
DSENTRYPROC dsEntry
Definition: twain_i.h:46
static struct all_devices * devices
Definition: dsm_ctrl.c:50
TW_STR32 ProductName
Definition: twain.h:264
#define DG_CONTROL
Definition: twain.h:1311
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
#define ERR(fmt,...)
Definition: debug.h:109
struct list pending_messages
Definition: twain_i.h:47
#define TWCC_SUCCESS
Definition: twain.h:1678
static TW_UINT16 DSM_initialized
Definition: dsm_ctrl.c:38
TW_UINT32 Id
Definition: twain.h:257
#define TWRC_FAILURE
Definition: twain.h:1665
#define TWCC_NODS
Definition: twain.h:1681
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
HMODULE hmod
Definition: twain_i.h:45
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define GetProcAddress(x, y)
Definition: compat.h:410
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
struct TW_IDENTITY * pTW_IDENTITY
Definition: twain.h:1762
#define HeapFree(x, y, z)
Definition: compat.h:394
#define TWCC_SEQERROR
Definition: twain.h:1687
#define MSG_OPENDS
Definition: twain.h:1409
#define DAT_IDENTITY
Definition: twain.h:1337

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_OpenDSM()

TW_UINT16 TWAIN_OpenDSM ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 486 of file dsm_ctrl.c.

487 {
488  TW_UINT16 twRC = TWRC_SUCCESS;
489 
490  TRACE("DG_CONTROL/DAT_PARENT/MSG_OPENDSM\n");
491  if (!DSM_initialized) {
492  event_message = RegisterWindowMessageA("WINE TWAIN_32 EVENT");
493  DSM_currentDevice = 0;
495  DSM_twCC = TWCC_SUCCESS;
496  twRC = TWRC_SUCCESS;
497  } else {
498  /* operation invoked in invalid state */
499  DSM_twCC = TWCC_SEQERROR;
500  twRC = TWRC_FAILURE;
501  }
502  DSM_parent = (HWND)pData;
503  return twRC;
504 }
#define TRUE
Definition: types.h:120
HANDLE HWND
Definition: compat.h:13
#define TWRC_SUCCESS
Definition: twain.h:1664
static UINT event_message
Definition: dsm_ctrl.c:42
unsigned short TW_UINT16
Definition: twain.h:119
static TW_UINT16 DSM_currentDevice
Definition: dsm_ctrl.c:40
static HWND DSM_parent
Definition: dsm_ctrl.c:41
#define TRACE(s)
Definition: solgame.cpp:4
#define TWCC_SUCCESS
Definition: twain.h:1678
static TW_UINT16 DSM_initialized
Definition: dsm_ctrl.c:38
#define TWRC_FAILURE
Definition: twain.h:1665
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
#define TWCC_SEQERROR
Definition: twain.h:1687
UINT WINAPI RegisterWindowMessageA(_In_ LPCSTR)

Referenced by TWAIN_SourceManagerHandler().

◆ TWAIN_ProcessEvent()

TW_UINT16 TWAIN_ProcessEvent ( pTW_IDENTITY  pOrigin,
activeDS pSource,
TW_MEMREF  pData 
)

Definition at line 164 of file dsm_ctrl.c.

165 {
166  TW_EVENT *event = (TW_EVENT*)pData;
167  MSG *msg = (MSG*)event->pEvent;
169 
170  TRACE("%x,%x\n", msg->message, event_message);
171 
172  if (msg->message == event_message)
173  {
174  if (!list_empty (&pSource->pending_messages))
175  {
176  struct list *entry = list_head (&pSource->pending_messages);
178  event->TWMessage = message->msg;
179  list_remove (entry);
180  TRACE("<-- %x\n", event->TWMessage);
181  }
182  else
183  event->TWMessage = MSG_NULL;
185  }
186 
187  if (msg->hwnd)
188  {
189  MSG dummy;
190  pSource->event_window = msg->hwnd;
191  if (!list_empty (&pSource->pending_messages) &&
193  {
194  PostMessageW(msg->hwnd, event_message, 0, 0);
195  }
196  }
197 
198  return result;
199 }
HWND event_window
Definition: twain_i.h:49
Definition: tftpd.h:59
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
uint8_t entry
Definition: isohybrid.c:63
#define MSG_NULL
Definition: twain.h:1381
static UINT event_message
Definition: dsm_ctrl.c:42
unsigned short TW_UINT16
Definition: twain.h:119
#define PM_NOREMOVE
Definition: winuser.h:1181
__WINE_SERVER_LIST_INLINE struct list * list_head(const struct list *list)
Definition: list.h:131
#define TWRC_DSEVENT
Definition: twain.h:1668
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
#define TWRC_NOTDSEVENT
Definition: twain.h:1669
Definition: _list.h:228
struct _cl_event * event
Definition: glext.h:7739
__WINE_SERVER_LIST_INLINE int list_empty(const struct list *list)
Definition: list.h:143
struct list pending_messages
Definition: twain_i.h:47
unsigned char dummy
Definition: maze.c:118
#define msg(x)
Definition: auth_time.c:54
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
#define LIST_ENTRY(type)
Definition: queue.h:175
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
GLuint64EXT * result
Definition: glext.h:11304

Referenced by DSM_Entry().

◆ TWAIN_UserSelect()

TW_UINT16 TWAIN_UserSelect ( pTW_IDENTITY  pOrigin,
TW_MEMREF  pData 
)

Definition at line 430 of file dsm_ctrl.c.

431 {
432  userselect_data param = {pOrigin, pData};
434 
435  TRACE("DG_CONTROL/DAT_IDENTITY/MSG_USERSELECT SupportedGroups=0x%x ProductName=%s\n",
436  pOrigin->SupportedGroups, wine_dbgstr_a(param.result->ProductName));
437 
439 
440  if (!IsWindow(parent))
441  parent = NULL;
442 
445  {
446  TRACE("canceled\n");
447  DSM_twCC = TWCC_SUCCESS;
448  return TWRC_CANCEL;
449  }
450 
451  TRACE("<-- %s\n", wine_dbgstr_a(param.result->ProductName));
452  DSM_twCC = TWCC_SUCCESS;
453  return TWRC_SUCCESS;
454 }
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
const char int int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:186
BOOL WINAPI IsWindow(_In_opt_ HWND)
static void twain_autodetect(void)
Definition: dsm_ctrl.c:108
#define TWRC_SUCCESS
Definition: twain.h:1664
TW_UINT32 SupportedGroups
Definition: twain.h:261
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
static HWND DSM_parent
Definition: dsm_ctrl.c:41
#define TRACE(s)
Definition: solgame.cpp:4
r parent
Definition: btrfs.c:2659
GLfloat param
Definition: glext.h:5796
#define TWRC_CANCEL
Definition: twain.h:1667
#define TWCC_SUCCESS
Definition: twain.h:1678
#define DLG_USERSELECT
Definition: resource.h:22
static INT_PTR CALLBACK userselect_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Definition: dsm_ctrl.c:354
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
HINSTANCE DSM_hinstance
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

Referenced by TWAIN_SourceManagerHandler().

◆ userselect_dlgproc()

static INT_PTR CALLBACK userselect_dlgproc ( HWND  hwnd,
UINT  msg,
WPARAM  wparam,
LPARAM  lparam 
)
static

Definition at line 354 of file dsm_ctrl.c.

355 {
356  switch (msg)
357  {
358  case WM_INITDIALOG:
359  {
361  int i;
362  HWND sourcelist;
363  BOOL any_devices = FALSE;
364 
366 
367  sourcelist = GetDlgItem(hwnd, IDC_LISTSOURCE);
368 
369  for (i=0; i<nrdevices; i++)
370  {
371  TW_IDENTITY *id = &devices[i].identity;
372  LRESULT index;
373 
374  if ((id->SupportedGroups & data->origin->SupportedGroups) == 0)
375  continue;
376 
377  index = SendMessageA(sourcelist, LB_ADDSTRING, 0, (LPARAM)id->ProductName);
378  SendMessageW(sourcelist, LB_SETITEMDATA, (WPARAM)index, (LPARAM)i);
379  any_devices = TRUE;
380  }
381 
382  if (any_devices)
383  {
385 
386  /* FIXME: Select the supplied product name or default source. */
387  SendMessageW(sourcelist, LB_SETCURSEL, 0, 0);
388  }
389 
390  return TRUE;
391  }
392  case WM_CLOSE:
393  EndDialog(hwnd, 0);
394  return TRUE;
395  case WM_COMMAND:
397  {
398  EndDialog(hwnd, 0);
399  return TRUE;
400  }
401  else if (wparam == MAKEWPARAM(IDOK, BN_CLICKED) ||
403  {
405  HWND sourcelist;
406  LRESULT index;
407 
408  sourcelist = GetDlgItem(hwnd, IDC_LISTSOURCE);
409 
410  index = SendMessageW(sourcelist, LB_GETCURSEL, 0, 0);
411 
412  if (index == LB_ERR)
413  return TRUE;
414 
415  index = SendMessageW(sourcelist, LB_GETITEMDATA, (WPARAM)index, 0);
416 
417  *data->result = devices[index].identity;
418 
419  /* FIXME: Save this as the default source */
420 
421  EndDialog(hwnd, 1);
422  return TRUE;
423  }
424  break;
425  }
426  return FALSE;
427 }
#define LB_SETCURSEL
Definition: winuser.h:2024
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
#define MAKEWPARAM(l, h)
Definition: winuser.h:3916
#define IDOK
Definition: winuser.h:824
#define LB_ADDSTRING
Definition: winuser.h:1992
LRESULT WINAPI SendMessageA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define LB_GETITEMDATA
Definition: winuser.h:2002
UINT_PTR WPARAM
Definition: windef.h:207
#define GetWindowLongPtrW
Definition: winuser.h:4698
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define LB_ERR
Definition: winuser.h:2386
unsigned int BOOL
Definition: ntddk_ex.h:94
static UINT WPARAM LPARAM lparam
Definition: combo.c:716
static int nrdevices
Definition: dsm_ctrl.c:49
LONG_PTR LPARAM
Definition: windef.h:208
GLuint index
Definition: glext.h:6031
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_CLOSE
Definition: winuser.h:1603
#define BN_CLICKED
Definition: winuser.h:1886
#define LB_SETITEMDATA
Definition: winuser.h:2026
#define LBN_DBLCLK
Definition: winuser.h:2032
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static struct all_devices * devices
Definition: dsm_ctrl.c:50
#define index(s, c)
Definition: various.h:29
#define DWLP_USER
Definition: winuser.h:866
#define WM_COMMAND
Definition: winuser.h:1716
#define IDC_LISTSOURCE
Definition: resource.h:24
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define LB_GETCURSEL
Definition: winuser.h:2000
#define msg(x)
Definition: auth_time.c:54
GLenum GLuint id
Definition: glext.h:5579
#define SetWindowLongPtrW
Definition: winuser.h:5215
#define IDCANCEL
Definition: winuser.h:825
LONG_PTR LRESULT
Definition: windef.h:209
#define WM_INITDIALOG
Definition: winuser.h:1715
static UINT WPARAM wparam
Definition: combo.c:716

Referenced by TWAIN_UserSelect().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( twain  )

Variable Documentation

◆ detectionrun

BOOL detectionrun = FALSE
static

Definition at line 105 of file dsm_ctrl.c.

Referenced by twain_autodetect().

◆ devices

◆ DSM_currentDevice

TW_UINT16 DSM_currentDevice
static

Definition at line 40 of file dsm_ctrl.c.

Referenced by TWAIN_IdentityGetFirst(), TWAIN_IdentityGetNext(), and TWAIN_OpenDSM().

◆ DSM_initialized

TW_UINT16 DSM_initialized
static

Definition at line 38 of file dsm_ctrl.c.

Referenced by TWAIN_CloseDSM(), TWAIN_OpenDS(), and TWAIN_OpenDSM().

◆ DSM_parent

HWND DSM_parent
static

Definition at line 41 of file dsm_ctrl.c.

Referenced by TWAIN_CloseDSM(), TWAIN_ControlNull(), TWAIN_OpenDSM(), and TWAIN_UserSelect().

◆ DSM_sourceId

TW_UINT32 DSM_sourceId
static

Definition at line 39 of file dsm_ctrl.c.

Referenced by twain_add_onedriver(), and TWAIN_OpenDS().

◆ event_message

UINT event_message
static

Definition at line 42 of file dsm_ctrl.c.

Referenced by TWAIN_ControlNull(), TWAIN_OpenDSM(), and TWAIN_ProcessEvent().

◆ nrdevices