Solved

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

Posted on 2004-04-19
5
1,154 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
ID: 10861232
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
ID: 10861910
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
ID: 10862057
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
ID: 10862291
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
ID: 10862340
Alex  !!

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

;-))

Eric.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

867 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

19 Experts available now in Live!

Get 1:1 Help Now