Visual Basic .NET Sample Program
The following Visual Basic .NET example all that is required to do the following:
Check if TWAIN is installed.
Initialize the DTWAIN Dynamic Link Library.
Select a Source
Acquire a page using the Native transfer mode
Save page to a BMP file called "test.bmp"
Shut down any open TWAIN Source's and DTWAIN itself
Private TwainOK As Integer
Private MyDTwain As DTWAINAPI
Private SelectedSource As Integer
Private RetVal As Integer
FileName As String = "test.bmp"
Dim Status As Integer
Rem Check if TWAIN is installed
TwainOK = .DTWAIN_IsTwainAvailable()
SelectedSource = 0
If TwainOK = 1 Then
Rem Initialize DTWAIN
TwainOK = .DTWAIN_SysInitialize()
Rem Select a TWAIN device
SelectedSource = .DTWAIN_SelectSource()
Acquire to a file.
if SelectedSource <> 0 Then
RetVal = .DTWAIN_AcquireFile( SelectedSource, FileName, .DTWAIN_BMP,
.DTWAIN_USENATIVE+DTWAIN_USENAME, .DTWAIN_PT_DEFAULT, 1, 1, Status)
Rem shut down TWAIN system and DTWAIN.
For Visual Basic .NET, the class DTWAINAPI is a class that wraps the DTWAIN functions. Note that it is as simple as calling five DTWAIN functions to get the job done.
The Visual Basic .NET project just adds the DTWAIN32_NET.BAS interface file to define the DTWAIN functions so that Visual Basic .NETwill recognize the functions such as DTWAIN_SysInitialize.
The documentation that comes with the DynaRithmic TWAIN Library discusses functions such as DTWAIN_AcquireFile in depth. It wasn't discussed here, but the goal of this small example is to show how simple it is to acquire images from a TWAIN device and save them to a file. To acquire to the other file types other than BMP, the parameter that specifies DTWAIN_BMP can be any of the other file types such as DTWAIN_GIF, DTWAIN_JPEG, etc.. Therefore just 5 calls can save a file to any of many file types by just changing the third parameter to DTWAIN_AcquireFile.