TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Reply To: Web Control Issue with TWAIN

Forums › TWAIN Classic › Web Control Issue with TWAIN › Reply To: Web Control Issue with TWAIN

August 20, 2009 at 7:01 pm #25016
mcohen
Participant
  • Topics - 2
  • Replies - 13
  • Total Posts - 15

I actually solved the problem (thanks for your response, though). But for those who may be curious on how I did it, here is the bottom line (Please, note that including all the code in this forum is a little complicated because it seats all over the place on different files. However, I will try to give you an idea):

From JavaScript I called a method “objScanner.AcquireImage()” of my UserControl “objScanner”. All this method did was to load an instance of my “frmMDI” form:

dim objMDI as new frmMDI

The OnLoad_Event of the MDI form would then create an “objTwain” object where all the calls to TWAIN were coded. Remember from my post that if I skipped the JavaScript code and the UserControl concept altogether and just compiled my application as an executable with the MDI as the startup object and installed on the client computer, all seemed to work fine. So the problem had to do with the right windows handle being passed to Twain. I have a method inside my form:

Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Dim objTwCommand As TwainLib.TW_COMMAND = objTwain.PassMessage(m)
Dim objNextPicture As frmPicture = Nothing
Dim intPictureIndex As Integer = Nothing
Dim objImagePointer As IntPtr = Nothing
Dim araPictures As ArrayList = Nothing
Dim intI As Integer
If objTwCommand = TwainLib.TW_COMMAND.TW_NOT Then
Return False
End If
Select Case objTwCommand
Case TwainLib.TW_COMMAND.TW_CLOSEREQUEST
EndingScan()
objTwain.CloseSrc()
Case TwainLib.TW_COMMAND.TW_CLOSEOK
EndingScan()
objTwain.CloseSrc()
Case TwainLib.TW_COMMAND.TW_DEVICEEVENT
Exit Select
Case TwainLib.TW_COMMAND.TW_TRANSFERREADY
araPictures = objTwain.TransferPictures()
EndingScan()
objTwain.CloseSrc()
intPictureIndex += 1
For intI = 0 To araPictures.Count – 1
objImagePointer = CType(araPictures(intI), IntPtr)
objNextPicture = New frmPicture(objImagePointer)
objNextPicture.MdiParent = Me
intPictureIndex = intI + 1
objNextPicture.Text = “ScanPass” + intPictureIndex.ToString() + “_Pic” + intPictureIndex.ToString()
objNextPicture.Show()
Next
objNextPicture = Nothing
End Select
Return True
End Function

… which would intercept all form events (TWAIN and non-TWAIN) and process them accordingly (Reading TWAIN documentation I learned that TWAIN sends all events to my application for pre-processing expecting it to return the favor by sending them back to the “Twain User Interface” for capturing. So if my application failed to capture the events, they would be lost causing the “Twain User Interface” to become unresponsive, which is exactly what happened).

To solve the problem, all I did was, instead of creating a new instance of the MDI form from my UserControl, I called the method:

Application.run(new frmMDI)

…and decorated the method with the “ _” attribute. Basically, this step runs my MDI on its own process avoiding confusion on which handled was passed. I think my interpretation is correct.

    Quick Links

    Service Providers
    TWAIN Support Forums
    Membership
    Contact Us
    Privacy Policy

    Newsletter Signup

    TWAIN Working Group Family

    TWAIN Working Group
    TWAIN Direct®
    TWAIN Resources
    TWAIN Certified Drivers
    PDF/raster

    • Facebook
    • GitHub
    • LinkedIn
    • Vimeo

    Recent Topics

    • TWAIN for dental imaging integration
    • PDF/R For who and where?
    • Making searchable PDF with PDF/R
    • Backward compatibility with PDF/A and traditional PDF
    • could not open the twain source. Make sure there is a valid source for your sca
    • Quarterly Newsletter
    • TWAIN Working Group Membership
    • Logo Usage
    • TWAIN License
    • Contact Us
    Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in