DTwainInterface::EnumSources

Top  Previous  Next

Syntax

static bool EnumSources( DTwainSourceArray & SourceArray );

 

Parameters

SourceArray

On successful return, all of the installed Sources are copied to this array.  Each element of the array is a DTwainSource.

 

Return Value

Returns true if successful, false otherwise.

 

Comments

Each element in the SourceArray is a DTwainSource type.  Note that the Sources that are in the DTwainSourceArray may not have been selected.  The DTwainInterface::EnumSources function only has DTwainSource's that are for informational use only (for example, getting the Product name of the Source).  There is no guarantee that the Sources contained in the returned DTwainSourceArray have been selected or can be used to acquire an image without being selected (see DTwainSource::Select for more information).

 

Example: Selecting a source using a name

 

#include <cdtwain.h>

using namespace DTWAIN;

 

int main( )

{

   // Initialize DTWAIN

   DTwainInterface TI;

 

   // Enumerate all the TWAIN Sources that are installed

   DTwainSourceArray SA;

   DTwainInterface::EnumSources ( SA );

 

   DTwainSource Source;

   if ( SA.size( ) > 0 )

   {

        // Select the first source found by using the Source product name

        DTwainSource Source = DTwainSource::Select( DTwainSourceInfo( SA[0] ).GetProductName( ) );

 

        //... The Source can now be used to acquire images...

       Source.Acquire("FILE.BMP":);

  }

}

 

The following program is not guaranteed to work correctly, since the Source has not been selected.

 

#include <cdtwain.h>

using namespace DTWAIN;

 

int main( )

{

   // Initialize DTWAIN

   DTwainInterface TI;

 

   // Enumerate all the TWAIN Sources that are installed

   DTwainSourceArray SA;

   DTwainInterface::EnumSources ( SA );

 

   DTwainSource Source = SA[0];

   if ( SA.size( ) > 0 )

   {

       SA[0].Acquire("FILE.BMP"); // error.  Source SA[0] was not selected

  }

}