C# and DTWAIN Notifications

Top  Previous  Next

Many times, the program that acquires an image needs to know the progress of the acquisition while it is being acquired.  The way that an application is informed of the acquisition process is by either intercepting messages within a Window procedure, or setting up a callback function.  Please see DTWAIN Notification processing for more details.

 

If you are using Visual C#, use the callback method of retrieving the DTWAIN notifications.  To set up a callback function in C#, the DTWAIN_SetCallback function must be used, and a delegate object must be created.  Here is a sample:

 

//...

//...

private static int CaptureTwainProc( int wParam, int lParam, int UserParam )

{

   if ( wParam == TwainAPI.DTWAIN_TN_TRANSFERREADY )

   {

       return 1;

   }

   return 1;

}  

 

static void Main()

{

  //...

  Dynarithmic.TwainAPI.DTWAIN_EnableMsgNotify(1);                

  Dynarithmic.TwainAPI.DTwainCallback cb = new TwainAPI.DTwainCallback( CaptureTwainProc );

  Dynarithmic.TwainAPI.DTWAIN_SetCallback(cb, 0 );

  //...

}

 

The CaptureTwainProc is a delegate function with three integer arguments.  All DTWAIN callbacks in C# must have the same function arguments (three int arguments).  The call to DTWAIN_SetCallback creates a new DTwainCallback delegate, using the CaptureTwainProc as the callback.

 

When the acquisition starts, CaptureTwainProc will be called by DTWAIN whenever a notification is sent.