DTWAIN Handles and Threading Issues

Top  Previous  Next

Internally, DTWAIN associates the handle returned by DTWAIN_SysInitialize or DTWAIN_SysInitializeEx with the current thread identifier (thread ID).  When a subsequent call to a DTWAIN API function is done, DTWAIN checks that the thread identifier originally used in DTWAIN_SysInitialize is still the current thread.  If not, a -1001 error (DTWAIN not initialized) is returned.

 

Therefore under normal circumstances, DTWAIN will not run across threads without some modifications, which are discussed below.


To overcome the -1001 error when using multiple threads, there are two scenarios possible:

 

1.

Running multiple sessions of DTWAIN, one session for each thread or

2.

Running a single session of DTWAIN in more than one thread.


To allow DTWAIN to be used in a multithreaded application, a call to DTWAIN_UseMultipleThreads(TRUE) must be done to ensure that the DTWAIN library will recognize it will be used in a multithreaded fashion.

 

In the following sections, references to DTWAIN_SysInitialize also apply to DTWAIN_SysInitializeEx.

 

Multiple DTWAIN Sessions

Single DTWAIN Session