Home › Forums › TWAIN Classic › Web Control Issue with TWAIN › Reply To: Web Control Issue with TWAIN
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 “