Home › Forums › TWAIN Classic › Windowless TWAIN session shutdown errors
- This topic has 2 replies, 3 voices, and was last updated 11 years ago by dpenney.
- AuthorPosts
Hi everyone,
I’m currently writing an application that interfaces with a Leica microscopy camera on Windows XP, and things have been going smoothly so far. The application is a simple web server that allows the microscope to be controlled from a different location. Because the application is a web server I have been preventing the TWAIN session from opening any windows and have set the hParent field of TW_USERINTERFACE to NULL when enabling the data source. The webserver has no window of its own, so there is nothing that I can set hParent to that will make sense.
Things work well until I attempt to shut the server down. At this point the data source cannot be disabled, and neither the data source or the data source manager can be closed successfully. From my experimentation I believe that this is due to the NULL value I gave to the hParent field of TW_USERINTERFACE. Is there a value that I should be giving the hParent field besides NULL for a windowless application? And does anyone have other ideas about why the source and source manager refuse to close, even if all I do is start open them, enable the source, and then immediately attempt to disable and close?
Thanks
Hi Theck01 –
It is not surprising that TWAIN or the Leica driver don’t work quite right when hParent = NULL, as the TWAIN specification does not allow for this possibility, or define the behavior of TWAIN in this case. What is surprising is that the Leica driver works at all in this situation 😮Are you intercepting messages in the message pump and forwarding them via MSG_PROCESSEVENT? And is your app receiving MSG_XFERREADY messages?
I’d suggest creating an invisible ‘proxy’ window and passing its handle in hParent. Destroy it after MSG_CLOSEDS is completed.
Even when an application sets ShowUI to false on MSG_ENABLEDS and CAP_INDICATORS to false, the DS may show UI. To see how it can do that while still be compliant with the specification, please read the section “Error and Device Control Indicators” in the TWAIN specification.
If that’s not a show stopper your webserver should create an window (as spike suggested) or call GetDesktopWindow() to get a valid HWND to use as the parent window. Note that if the webserver is a Windows service it should not call TWAIN since it may need to display UI.
@theck01 wrote:
Hi everyone,
I’m currently writing an application that interfaces with a Leica microscopy camera on Windows XP, and things have been going smoothly so far. The application is a simple web server that allows the microscope to be controlled from a different location. Because the application is a web server I have been preventing the TWAIN session from opening any windows and have set the hParent field of TW_USERINTERFACE to NULL when enabling the data source. The webserver has no window of its own, so there is nothing that I can set hParent to that will make sense.
Things work well until I attempt to shut the server down. At this point the data source cannot be disabled, and neither the data source or the data source manager can be closed successfully. From my experimentation I believe that this is due to the NULL value I gave to the hParent field of TW_USERINTERFACE. Is there a value that I should be giving the hParent field besides NULL for a windowless application? And does anyone have other ideas about why the source and source manager refuse to close, even if all I do is start open them, enable the source, and then immediately attempt to disable and close?
Thanks
- AuthorPosts