Implementing a wait loop for Modeless Acquisitions

Top  Previous  Next

For modeless acquisitions, acquisition functions such as DTWAIN_AcquireNative return immediately when called.  This becomes a problem if your application desires to wait until the acquisition session has terminated before moving on.  For cases such as this, the application must enter a "wait" or "idle" loop until the acquisitions are done.  The following C / C++ code will perform this job:

 

/* Call an acquisition function */

MSG msg;

int val;

/* ... */

DTWAIN_AcquireFIle( Source,  ... );  // This will return immediately if DTWAIN_SetTwainMode( DTWAIN_MODELESS) was called

 

/* Perform a loop until acquisitions are done */

   while (((val = GetMessage (&msg, NULL, 0, 0)) != -1) // while there is a message

           && DTWAIN_IsUIEnabled(Source))         // and the Source is acquiring

   {

       if ( val != 0 )

       {

           if ( !DTWAIN_IsTwainMsg(&msg) )  // send message to TWAIN if DTWAIN message

           {

               TranslateMessage (&msg);    // send message to app, not TWAIN

               DispatchMessage (&msg);

           }

       }          

   }

 

Remember that this loop is necessary only if:

 

a) Modeless processing is used and

b) You want your application to "wait" until the acquisitions are done.