Managing the TWAIN Source

After establlishing a handle to a TWAIN session by calling either L_TwainInitSession or L_TwainInitSession2, select the TWAIN source to be used for acquiring images.

The LEADTOOLS TWAIN toolkit provides the following functions for managing TWAIN data sources installed on a system:

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:

selectsourcedialogwithtwain2driverselected.png

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:

selectsourcedialogwithtwain1driverselected.png

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.

See Also

Help Version 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS TWAIN C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.