Solved

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

Posted on 2004-04-19
5
1,166 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
[X]
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
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month6 days, 21 hours left to enroll

622 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