Home › Forums › TWAIN Classic › Web Control Issue with TWAIN
- This topic has 2 replies, 2 voices, and was last updated 14 years, 8 months ago by mcohen.
- AuthorPosts
Hi all.
I am building a Twain Control that is deployed over the Internet to client applications. This Control is built as a “Class Library” which generates an “MDI Form” upon activation. Clients use JavaScript to call my public method “Scan” exposed by the “Class Library”. This method creates an instance of the MDI form and loads it into memory. When the MDI form loads, it initializes a Twain object using its own windows handle or pointer to the Triplet Operation TW_DG.DG_CONTROL, TW_DAT.DAT_PARENT, TW_MSG.MSG_OPENDSM which in turn returns a SUCCESS code. Twain then loads the “Source Manager” successfully where I am able to select a “Twain Source”. After selecting a source I get the expected “Twain User Interface” which is able to “PreScan” without a problem. However, all other options are unresponsive, including the “Scan Button” (Actually, if there is no paper on the scanner, the “Scan Button” does respond with a “No Paper” error message, but if there is paper it becomes unresponsive). You should note several things I’ve attempted or checked:
1.- When running the Triplet Operation TW_DG.DG_CONTROL, TW_DAT.DAT_USERINTERFACE, TW_MSG.MSG_ENABLEDS, the response code is TW_RC.TWRC_SUCCESS, so I assume there is no problem on that end.
2.- I have a function “PreFilterMessage” that is constantly querying the Twain object for any Events that maybe generated. This function doesn’t seem to be getting any messages at all from the Twain object.
3.- The same code works without glitch if I deploy the application to the client as an executable where the MDI form is the startup object.The problem seems to be related to event handling of some sort. Somehow the windows handle or pointer gets lost or is the wrong one, but I can’t figure out why or how to fix it…
Any help would be greatly appreciated.
without seeing any code I’m going to guess that your messagepump isn’t quite right – unresponsive controls are allllmost always due to messagepumping problems.
if you post some code someone here can probably help – even if it is just a slimmed down version of the code that reproduces the problem.
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. - AuthorPosts