• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 548
  • Last Modified:

WANG scan control

Could anyone explain the pros and cons of the WANG Image Scan control and if it is worth adding to my application.  I considered using this control in my app.  I would like to use the TWAIN interface because I heard it was better but I have never used it.  Part of my app requires me to scan and save images.  Also, if someone shows me how to use the TWAIN interface (with code), I will add 400 points to this question.  This is not necessary though.
  • 4
1 Solution
' 32-bit EZTWAIN functions for Visual Basic 5.0
Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp&, ByVal wPixTypes&) As Long
Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" (ByVal hwndApp&) As Long

'On Form1
'Add Picture1
'Add Command1 and Command2
'Add following code
Private Sub Command1_Click()
r = TWAIN_SelectImageSource(Me.hWnd)
End Sub

Private Sub Command2_Click()
r = TWAIN_AcquireToClipboard(Me.hWnd, t%)
Picture1.Picture = Clipboard.GetData(vbCFDIB)

End Sub
You can do this with the freeware eztw32.dll. I can't remember where I got it, so you can download it from


Here is a code module that handles it :

Option Explicit

' 32-bit EZTWAIN functions for Visual Basic 5.0

' Acquires a single scan and returns it as a DIB handle
Declare Function TWAIN_AcquireNative Lib "EZTW32.DLL" (ByVal hwndApp%, ByVal wPixTypes%) As Integer

' Releases the storage for a DIB handle
Declare Sub TWAIN_FreeNative Lib "EZTW32.DLL" (ByVal hdib%)

' Acquires a single scan and places it on the clipboard as a DIB
Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp%, ByVal wPixTypes%) As Integer

' Acquires a single scan and writes it to a .BMP file
' If bmpFileName$ is empty, prompts user for filename.
Declare Function TWAIN_AcquireToFilename Lib "EZTW32.DLL" (ByVal hwndApp%, ByVal bmpFileName$) As Integer
' Posts the standard TWAIN Select Source dialog
Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" (ByVal hwndApp%) As Integer

' returns 1 if TWAIN is available on host system, 0 otherwise.
Declare Function TWAIN_IsAvailable Lib "EZTW32.DLL" () As Integer

' returns the EZTWAIN version * 100 i.e. 105 for version 1.05
Declare Function TWAIN_EasyVersion Lib "EZTW32.DLL" () As Integer

' returns the TWAIN state - see TWAIN.H or EZTWAIN.H
Declare Function TWAIN_State Lib "EZTW32.DLL" () As Integer

Declare Function TWAIN_WriteNativeToFilename Lib "EZTW32.DLL" (ByVal hBitmap%, ByVal bmpFileName$) As Integer

' returns the number of bits per pixel of a DIB (given the DIB handle)
Declare Function TWAIN_DibDepth Lib "EZTW32.DLL" (ByVal hdib%) As Integer

' returns the width in pixels of a DIB (given the DIB handle)
Declare Function TWAIN_DibWidth Lib "EZTW32.DLL" (ByVal hdib%) As Integer

' returns the height in pixels of a DIB (given the DIB handle)
Declare Function TWAIN_DibHeight Lib "EZTW32.DLL" (ByVal hdib%) As Integer

' returns the size of the colortable of a DIB (given the DIB handle)
' DIBs deeper than 8 bits have no colortable and will return 0.
Declare Function TWAIN_DibNumColors Lib "EZTW32.DLL" (ByVal hdib%) As Integer

' TifDLL Error Codes

Public Function TiffError(ByVal R As Long) As String

    Select Case R
        Case 32501
            TiffError = "Unspecified Internal Error"
        Case 32502
            TiffError = "Unsupported Image Format (Please check the files with DIL extensions)."
        Case 32504
            TiffError = "File Not Found"
        Case 32506
            TiffError = "Insufficient Memory"
        Case 32210
            TiffError = "File Already Exists"
        Case 32211
            TiffError = "Error Opening File"
        Case 32511
            TiffError = "Error Printing Image"
        Case 32515
            TiffError = "Missing DIL file"
        Case 33202
            TiffError = "Missing DEL file"
        Case 33203
            TiffError = "Unsupported Export Format (please check the files with DEL extensions)."
        Case 33205
            TiffError = "Insufficient Memory"
        Case 33208
            TiffError = "Bad Dynamic Export Library"
        Case Else
            TiffError = "Unknown TiffDLLError " & Format$(R)
      End Select

End Function

and here is code that handles scans a picture to file :

Public Function ScanPictureToFile(ByVal FileName As String) As String

   On Local Error Resume Next

   Dim foo As Integer
   Dim F As Integer
   Dim c As String
   Dim R As Long
   FileName = Trim$(FileName)
   If Len(FileName) = 0 Then
     ScanPictureToFile = "The filename to save the file to is invalid."
     Exit Function
   End If
   F = FreeFile
   Open FileName For Output As #F
   Print #F, "Test"
   Close #F
   Kill FileName
   If Err <> 0 Then
     Err = 0
     ScanPictureToFile = "The picture cannot be save to the specified filename. Error is " & Error$(Err)
     Exit Function
   End If
   Screen.MousePointer = vbHourglass
   foo = TWAIN_AcquireToClipboard(ByVal 0, ByVal 0)
   If (foo = 0) Then
      ScanPictureToFile = "A Problem was encountered while attempting to aquire the image. Please try again."
      Screen.MousePointer = vbDefault
      Exit Function
   End If
   Image1.Picture = Clipboard.GetData(vbCFDIB)
   If Err <> 0 Then
     ScanPictureToFile = "An Error occurred while transferring the image from the clipboard to memory. The problem was identified as " & Error$(Err)
     Screen.MousePointer = vbDefault
     Exit Function
   End If
   If StrComp(Format, "bmp", vbTextCompare) = 0 Then
     SavePicture Image1.Picture, FileName
     If Err <> 0 Then
       ScanPictureToFile = "An Error occurred while attempting to save the image. The problem was identified as " & Error$(Err)
       Screen.MousePointer = vbDefault
       Exit Function
     End If
     ScanPictureToFile = "" 
     Exit Function
   End If
   Screen.MousePointer = vbDefault
   ScanPictureToFile = "" 

End Function

For this to work, you need to have an Image Control called Image1 on the form where you implement the function. I grabbed this from some code I wrote around 2 years ago. It actually uses another library to save as GIF, JPG or so but as it's commercial I had to strip it from this code. I hope the stripping did not introduce any errors

Search criteria: +"visual basic question" vb +scanner -wang

Result: 20 topics


Want to perform another search?
Take a look at http://www.experts-exchange.com/jsp/qShow.jsp?ta=commspt&qid=10167777 

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now