Solved

Scanning APP in VB using TWAIN, EZTWAIN, ...

Posted on 2004-04-19
5
1,153 Views
Last Modified: 2007-12-19
Hello,

              Which tool set is more appropriate to develop scanning App in VB ?

              May be there are some other ones I am not aware of ?

Thank You,
-Alex
0
Comment
Question by:AlexF777
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
BeerMan earned 500 total points
Comment Utility
Hi !

You can use this  module,  work really fine for me :
(Comment the Line   SetErrFromErr  Function )


Public Function GetTwainVersion() As String
    Const msFunctionName            As String = "GetTwainVersion"
    Dim lRet                        As Long
    On Error GoTo ErrHandler
   
    lRet = TWAIN_EasyVersion()
    If lRet > 0 Then
        GetTwainVersion = CStr(lRet / 100)
    Else
        GetTwainVersion = "0"
    End If
   
ErrContinu:
    Exit Function
ErrHandler:
    Call SetErrFromErr(m_sModuleName, msFunctionName)
    Resume ErrContinu
End Function

Public Function IsTwainOk() As Boolean
    Const msFunctionName            As String = "IsTwainOk"
    Dim lRet                        As Long
    On Error GoTo ErrHandler
   
    lRet = TWAIN_IsAvailable()
   
    IsTwainOk = IIf(lRet = 0, False, True)
   
ErrContinu:
    Exit Function
ErrHandler:
    Call SetErrFromErr(m_sModuleName, msFunctionName)
    Resume ErrContinu
End Function

Public Function SelectTwain(ByVal lhWnd As Long) As Boolean
    Const msFunctionName            As String = "SelectTwain"
    Dim lRet                        As Long
    On Error GoTo ErrHandler
   
    lRet = TWAIN_SelectImageSource(lhWnd)
   
    SelectTwain = IIf(lRet = 0, False, True)
   
ErrContinu:
    Exit Function
ErrHandler:
    Call SetErrFromErr(m_sModuleName, msFunctionName)
    Resume ErrContinu
End Function

Public Function GetTwainToClipB(ByVal lhWnd As Long, _
                       Optional ByVal bClearClipBAfter As Boolean = False) _
                       As Picture
    ''
    Const msFunctionName            As String = "GetTwainToClipB"
    Dim lRet                        As Long
    On Error GoTo ErrHandler
   
    lRet = TWAIN_AcquireToClipboard(lhWnd, 0&)
   
    If lRet = 1 Then
        Set GetTwainToClipB = Clipboard.GetData(vbCFDIB)
        If bClearClipBAfter Then Call Clipboard.Clear
    End If
   
ErrContinu:
    Exit Function
ErrHandler:
    Call SetErrFromErr(m_sModuleName, msFunctionName)
    Resume ErrContinu
End Function

Public Function GetTwainToPic(ByVal lhWnd As Long, _
                     Optional ByVal sPathFileName As String = vbNullString) _
                     As Picture
    ''
    Const msFunctionName            As String = "GetTwainToPic"
    Dim lRet                        As Long
    Dim bKillFile                   As Boolean
    On Error GoTo ErrHandler
   
    If sPathFileName = vbNullString Then
        sPathFileName = GetTmpFileNameTwn(GetWinTempDirTwn(), "TWN")
        bKillFile = True
    End If
   
    lRet = TWAIN_AcquireToFilename(lhWnd, sPathFileName)
   
    If lRet = 0 Then
        Set GetTwainToPic = LoadPicture(sPathFileName)
    End If
   
    If bKillFile Then Call Kill(sPathFileName)
   
ErrContinu:
    Exit Function
ErrHandler:
    Call SetErrFromErr(m_sModuleName, msFunctionName)
    Resume ErrContinu
End Function


Public Function GetWinTempDirTwn(Optional ByVal bWithBackSlash As Boolean = True) As String
    Dim sFolder           As String
    Dim sSendStr               As String
    Dim retLng              As Long
    Const m_FunctionName    As String = "GetWinTempDirTwn"
    On Error GoTo ErrHandler
   
    sFolder = String(MAX_PATH, mZero)
   
    retLng = GetTempPath(MAX_PATH, sFolder)
    If retLng <> mZero Then
        sSendStr = Left(sFolder, InStr(sFolder, Chr$(mZero)) - mOne)
        If bWithBackSlash And (Right$(sSendStr, mOne) <> mBSlash) Then sSendStr = sSendStr & mBSlash
    Else
        sSendStr = vbNullString
    End If
   
    GetWinTempDirTwn = sSendStr
   
ErrContinu:
    Exit Function
ErrHandler:
    Call SetErrFromErr(m_sModuleName, m_FunctionName)
    Resume ErrContinu
End Function

Public Function GetTmpFileNameTwn(ByVal sDir As String, ByVal sPrefixe As String) As String
    Const m_FunctionName    As String = "GetTmpFileNameTwn"
    Dim sTempFilename       As String * MAX_PATH
    On Error GoTo ErrHandler
   
    sTempFilename = String$(Len(sTempFilename), mZero)
    Call GetTempFileName(sDir, sPrefixe, mZero, sTempFilename)
    GetTmpFileNameTwn = Mid$(sTempFilename, mOne, InStr(sTempFilename, Chr$(mZero)) - mOne)
   
ErrContinu:
    Exit Function
ErrHandler:
    Call SetErrFromErr(m_sModuleName, m_FunctionName)
    Resume ErrContinu
End Function



Have a nice Day.
Eric.
0
 

Author Comment

by:AlexF777
Comment Utility
Eric,

            Thanks.

            This code uses  EZTWAIN, right  ?

            What dll's do I need to reference ?

-Al
0
 
LVL 1

Assisted Solution

by:BeerMan
BeerMan earned 500 total points
Comment Utility
Alex,

Yes the file  Eztw32.dll,  but no need reference, it's an API, you just need to put
the file in System directory   (System32)  and use the API declaration (SORRY i forget it)

Option Explicit

''**************************************************
''
'' Programmed by :  Eric Laviolette
'' Email         :  vb@ExpertLogisoft.com
''
'' -------------------------------------------------
''
'' Start: 2003
'' ¯¯¯¯¯
'' Modify:
'' ¯¯¯¯¯¯
'' 14/01/2004
''
''**************************************************


Private Const m_sModuleName         As String = "modTwain.bas"
''
Private Const mZero                 As Long = 0
Private Const mOne                  As Long = 1
Private Const mBSlash               As String = "\"
''
Private Const MAX_PATH = 260
''
Private Declare Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
''
Private Declare Function TWAIN_AcquireToFilename Lib "EZTW32.DLL" (ByVal hwndApp As Long, ByVal bmpFileName As String) As Long
Private Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" (ByVal hwndApp As Long) As Long
Private Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp As Long, ByVal wPixTypes As Long) As Long
Private Declare Function TWAIN_IsAvailable Lib "EZTW32.DLL" () As Long
Private Declare Function TWAIN_EasyVersion Lib "EZTW32.DLL" () As Long
''

Thanks

Eric L.
0
 

Author Comment

by:AlexF777
Comment Utility
Hey, Eric

       What kind of beer do you prefer ?

       If this works for me ( I will probably know within 2 weeks as we did not connect to hardware yet ),
       I can send you some :)

Thank You,
-Alex

       
             
0
 
LVL 1

Expert Comment

by:BeerMan
Comment Utility
Alex  !!

Thanks,  a prefer  Blue Beer from Quebec ,  but i love international Beer Too !

;-))

Eric.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 64
SSRS expression Issue finding a string 10 50
Visual Basic Excel Formatting error 4 66
How does CurrentUser work? 10 25
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now