Twain Feeder: Tutorial #1

Take the following steps to start a project and to add some code that acquires the images using Fast Twain:

1.

Start Visual Basic.

2.

Add the LEAD RasterTwain Object Library and LEAD Raster Variant Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD RasterTwain Object Library (14).

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library (14).

3.

Add the LEAD Raster IO Object Library to your project. On the Project pull-down menu, use the References option, and select the LEAD Raster IO Object Library (14).

4.

Add the following code to the general declarations section of your project:

Public TwainCap As New LEADTwainCapability
Public WithEvents RasterTwain As LEADRasterTwain

5.

Add the following code to the main form's Load procedure:

Set RasterTwain = New LEADRasterTwain
RasterTwain.InitSession hWnd
RasterTwain.EnableMethodErrors = False

6.

Add the following code to the main form's Unload procedure:

RasterTwain.EndSession

7.

Add the following button:

 

Name

Caption

 

cmdAcquire

Acquire

8.

Code the Acquire control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

Private Sub cmdAcquire_Click()
   Dim bEnable As Boolean
   Dim nRet As Integer

   RasterTwain.SelectSource
   
   TwainCap.CapInfo.Capability = L_CAP_AUTOFEED
   TwainCap.CapInfo.ConType = L_TWON_ONEVALUE

   bEnable = True
   Dim RasVar As New LEADRasterVariant
   RasVar.Type = VALUE_BOOLEAN
   RasVar.BooleanValue = bEnable
   
   TwainCap.CapOneValue.OneValItemType = L_TWTY_BOOL
   TwainCap.CapOneValue.OneValCapValue = RasVar

   nRet = RasterTwain.SetCapability2(TwainCap, L_LTWAIN_CAPABILITY_SET) 
   If nRet = 0 Then
      MsgBox "AutoFeed capability is enabled"
   Else
      MsgBox "Can't enable AutoFeed capability"
   End If

   ' try to acquire pages using AutoFeed capability
   RasterTwain.Acquire L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_MODAL_USER_INTERFACE
End Sub