The LEADTOOLS TWAIN toolkit provides the following functions for managing TWAIN data sources installed on a system:
L_TwainSelectSource displays a dialog that lists all available TWAIN sources installed on the system and allows a TWAIN source to be selected. Note that calling L_TwainSetVersion affects any subsequent calls to L_TwainSelectSource for the rest of the session.
L_TwainGetSources enumerates either all available TWAIN sources, or the currently selected TWAIN source. For each source, the name, product family name, manufacturer name, and supported TWAIN version is retrieved. The LTWAINSOURCEINFOCALLBACK is called for each TWAIN source enumerated.
L_TwainGetVersion gets the TWAIN specification version currently being used.
L_TwainSetVersion sets which TWAIN specification version to use. Note that calling L_TwainSetVersion changes the behavior of L_TwainSelectSource. For more information, refer to Setting which TWAIN Specification Version to use.
Source control can be handled automatically or explicitly.
Automatic Source Control
To select the TWAIN source to be used for acquiring images, call the L_TwainSelectSource function. The toolkit automatically loads the TWAIN version DLL, depending on the default selected TWAIN driver. If the default selected source/driver supports TWAIN 2.x, the toolkit will try to load TWAIN 2.x. If it does not support TWAIN 2.x or the DLL cannot be loaded, the toolkit will try to load TWAIN 1.x. The data sources shown in the Select Source dialog depend on which TWAIN version is selected.
As an example, suppose two TWAIN data sources are available to a system:
1. Virtual TWAIN driver (named as TWAIN2 FreeImage Software Scanner), which supports TWAIN 2.x
2. FUJITSU scanner, which supports TWAIN 1.x
If TWAIN 2.x is selected as the TWAIN version, calling L_TwainSelectSource shows the following Select Source dialog:
If the FUJITSU source is selected (by selecting the FUJITSU entry and clicking Select), the toolkit automatically switches the version to TWAIN 1.x since that is the version of TWAIN that particular data source supports.
Now calling L_TwainSelectSource shows the following Select Source dialog:
Note that the listing in the Select Source dialog is different this time because the entries are now for drivers that meet the TWAIN 1.x specification.
Manual Source Control
It is also possible to override the default behavior and specify which version of TWAIN the selected device will use. To do so, call L_TwainSetVersion and pass “TWAIN_VERSION1” to use version 1.9, or “TWAIN_VERSION2” to use version 2.x. The version selected will be used for the rest of that particular session.
Note: Calling L_TwainSetVersion changes toolkit behavior. L_TwainSetVersion turns responsibility for performing driver/data source compatibility checks over to the user for the rest of the session, instead of letting the toolkit handle that automatically itself. If L_TwainSelectSource is called AFTER calling L_TwainSetVersion, automatic version checking will not be performed. A different source can still be selected, but the toolkit will continue to use the version of TWAIN that was set by L_TwainSetVersion. This is useful when the TWAIN 2.x DLL is installed on the system, but for some reason that version does not work correctly with a TWAIN device which uses the TWAIN 1.9 specification.