Home › Forums › TWAIN Classic › How to set default scanner source in program code?
- This topic has 5 replies, 4 voices, and was last updated 10 years, 5 months ago by sunshine_ak.
- AuthorPosts
Hello!
I need in my program to set default data source witout using GUI.
How can I do it?I know how to get default data source, how to get list of all data sources,
but I have not found the way to set default data source without GUI.Thanks in advance,
MichaelAccording to TWAIN Specification 2.2:
Selecting a Data Source
If the application wishes to use the default data source, it can issue the DG_CONTROL /
DAT_IDENTITY / MSG_GETDEFAULT command. This is preferred to calling DG_CONTROL /
DAT_IDENTITY / MSG_OPENDS with an empty structure.If the application wishes to get the list of available data sources it uses DG_CONTROL /
DAT_IDENTITY / MSG_GETFIRST and DG_CONTROL / DAT_IDENTITY / MSG_GETNEXT,
retaining the TW_IDENTITY of the data source it wants to use. This structure must not be
modified in any way.HTH
Catherine Sea
http://www.dynamsoft.comTake a look at DG_CONTROL / DAT_IDENTITY / MSG_SET.
In the TWAIN Specification version 2.2, it is at section 7 page 69.Problem: This feature was only introduced in TWAIN 2.2, so you would have to make sure the TWAIN Manager you are talking to understands TWAIN 2.2 or later.
I am not sure that any of the TWAIN managers (twain_32.dll) distributed with Windows support this feature… maybe somebody else can chime in here?
You may have to use the newer TWAINDSM.DLL, so you would have to either work with the user to make sure a new enough version is installed, or you could include recent version of TWAINDSM.DLL as part of your install. (Being careful to put it in the right folder, not overwrite a newer version, etc.)This really isn’t a recommended thing to do, because it sets the default TWAIN device for *all* TWAIN applications for the current user.
More customary is for the application to- enumerate the available scanners (with DAT_IDENTITY/MSG_GETFIRST,MSG_GETNEXT)
- let the user select the application’s current scanner from that list (using a drop-list or listbox)
- save that selection e.g. in the registry
- when asked to scan, use that (application-specific) scanner choice
Hello,
I have twain_32.dll, version 1.7 and I can’t use DG_CONTROL / DAT_IDENTITY / MSG_SET combination.
I have also Twack_32 in version 1.8 and it can set default scanner (in registry) by Twain interface dialog “select scanner”.How this default scanner is being set in registry, while I cannot use DG_CONTROL / DAT_IDENTITY / MSG_SET?
Does the Twain “select scanner” dialog work in other way?
Is there any other way to set default scanner in my case?The Select Source dialog can set the default TWAIN device because that dialog is owned and displayed by the TWAIN Manager, so it has access to internal functions of the manager (that you don’t have access to).
Can I ask (again) why you think you need to do this?
The default TWAIN device is a *user-wide* setting, affecting all applications. If you are trying to set that, you are taking on some of the function of the TWAIN manager, so your application should be some kind of ‘TWAIN management utility’ or ‘Scanner management utility’. And even then, why not just display the standard Select Source dialog?If your application just scans (like many other applications) then it has no business changing the default TWAIN device for all other scanning applications.
If you just need a way for the user of your application to select the scanner *your application* will use, then show the user the list of TWAIN devices, let him or her pick, and then store the name of the selected scanner as part of the configuration of your application, and then scan from that scanner.
Are you trying to fool some other application into scanning from a scanner that your application selects?
Thank you for answer.
I wanted to simply set default scanner without any additional processes (like writing entry to registry).
It would be also useful for me to set default scanner in such way for scanners installed on servers and accessed through Terminal Server, so every user would use the same scanner.But I appreciate your advices and I will use the solution with setting scanner only for my application.
- AuthorPosts