Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


WANG scan control

Posted on 1999-07-12
Medium Priority
Last Modified: 2012-05-04
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.
Question by:NeedAnswer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
LVL 13

Expert Comment

ID: 1524129
' 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
LVL 13

Accepted Solution

Mirkwood earned 400 total points
ID: 1524130
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

LVL 13

Expert Comment

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

Result: 20 topics 

Want to perform another search?
Take a look at 


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question