Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1176
  • Last Modified:

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

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
AlexF777
Asked:
AlexF777
  • 3
  • 2
2 Solutions
 
BeerManCommented:
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
 
AlexF777Author Commented:
Eric,

            Thanks.

            This code uses  EZTWAIN, right  ?

            What dll's do I need to reference ?

-Al
0
 
BeerManCommented:
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
 
AlexF777Author Commented:
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
 
BeerManCommented:
Alex  !!

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

;-))

Eric.
0

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!

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