GetMessage v. PeekMessage loops

Top  Previous  Next

When acquiring images from the TWAIN device, DTWAIN must start an application loop that runs until the acquisitions are terminated.  The application loop will consist of calling the Windows API PeekMessage function, or GetMessage function.


The difference between PeekMessage and GetMessage is that PeekMessage uses a non-blocking message loop, with the thread continually running.  The GetMessage uses a blocking message loop (the application has to "manually" retrieve messages from the message queue before the thread continues).


The DTWAIN library will attempt to detect whether the user-application language requires PeekMessage() processing over GetMessage().  There are some environments (for example scripting languages like Macro Schedulre) that require GetMessage() loops to be used.  DTWAIN will prioritize using PeekMessage as this will work with the majority of TWAIN Data Sources and programming enviroments.




Forcing usage of GetMessage over PeekMessage


It has been discovered that a small amount of TWAIN Sources will only work correctly if the API GetMessage is used in an infinite loop, or that the programming envrionment (usually scripting languages such as Macro Scheduler or similar) will only work by using GetMessage.  You will be able to determine this if for some reason, the Source's user-interface does not respond to mouse clicks, or basically most user interaction.


There are two main methods of having the GetMessage loop to be used instead of PeekMessage :


1) Adding the Product Name of the device to the [TwainLoopGetMsg] in the dtwain32.ini or dtwain64.ini file, or


2) Calling the DTWAIN_EnablePeekMessageLoop function with FALSE as the argument.  Note that this function works for individual Source's (since the first parameter to this function requires a Source).  

 

For method 1), the Product Name can be the full name, or a name with a wildcard that matches any source with the Product Name specified.  For example:


[TwainLoopGetMsg]

MyScanner*=1


will match any Source with the Product Name starting with "MyScanner".  Note that the name is case insensitive.  The =1 denotes that any Source with starts with that name will use GetMessage when performing the TWAIN message loop.





Forcing usage of PeekMessage over GetMessage


To turn off all detection of GetMessage and force the usage of PeekMessage regardless of the TWAIN Source, the DTWAIN_EnableGetMessageLoopDetection function should be called with a FALSE argument.  


The GetMessage() processing for an individual TWAIN Source can still be turned on by calling DTWAIN_EnablePleesMessageLoop with a FALSE argument for the individual Source.