Example: Get All Source Information

Top  Previous  Next

This example returns a DTWAIN_ARRAY that contains all of the DTWAIN_SOURCEs that are installed in the system.  If no Sources are found, an empty DTWAIN_ARRAY is returned.  If there was an error in getting the Source information, a NULL is returned.

 

#include <dtwain.h>

#include <tchar.h>

 

DTWAIN_SOURCE MySource;

LONG nSources;

DTWAIN_ARRAY SourceArray;

TCHAR szProductName[256];

 

/* For this example, assume that DTWAIN_SysInitialize() has been called successfully */

void SourceInfo(  )

{

   /* Get all of the Sources installed (note the use of the address of the DTWAIN_ARRAY) */

  DTWAIN_EnumSources(&SourceArray);

 

   /* Get the number of sources */

   nSources = DTWAIN_ArrayGetCount( SourceArray );

 

   /* return if none found */

   if ( nSources == 0 )

   {

      DTWAIN_ArrayDestroy(SourceArray );

       return;

   }

   else /* Sources were found */

   {

       int Count;

       TCHAR szBuf[1000];

       for (Count=0; Count < nSources; ++Count )

       {

           /* Get DTWAIN_SOURCE from Array*/

          DTWAIN_ArrayGetAt(SourceArray, Count, &MySource );

          DTWAIN_GetSourceProductName(MySource, szProductName, 255 );

          wsprintf(szBuf, _T("Source Name is %s"), szProductName);

          MessageBox(NULL, szBuf, _T("Source Info"), MB_OK);

      }    

      DTWAIN_ArrayDestroy( SourceArray );

  }

}