Example 10: Get Capabilities |
Top Previous Next |
Example: Examples of getting various Twain device capabilities. Illustrated are the gamma values (double values), transfer mechanisms ( long values ), and author (string value).
#include "cdtwain.h" #include <iostream> #include <string>
using namespace DTWAIN; using namespace std;
// Function to display all values of that have been retrieved from the Source that have // been stored in "ArrayType". Note that the arrays are actually STL vectors, so any // std::vector operations will work.
template <typename ArrayType> void DisplayAllCapValues(const std::string& CapName, const std::string& CapOp, const ArrayType& AT) { cout << "Capability values for " << CapName << endl << "Cap operation = " << CapOp << endl; ArrayType::const_iterator it = AT.begin( ); ArrayType::const_iterator it2 = AT.end( ); if ( it == it2 ) cout << "No values are available..." << endl; else { while ( it != it2 ) { cout << *it << endl; ++it; } cout << endl; } }
int main( ) { LONG CapOpType[] = { DTWAIN_CAPGET, DTWAIN_CAPGETCURRENT, DTWAIN_CAPGETDEFAULT }; char *CapOpName[] = {"Get Values", "Get Current Values", "Get Default Values"};
// Initialize DTWAIN - return if initialization does not work DTwainInterface TI; if ( !TI.IsValid( ) ) return 0;
// Select a Source DTwainSource Source = DTwainSource::Select( ); if ( !Source.IsValid( ) ) return 0;
// Get the Gamma value of the Source DTwainDoubleArray GammaValue; int i; for ( i = 0; i < 3; ++i ) { Source.GetCapValues( DTWAIN_CV_ICAPGAMMA, GammaValue, CapOpType[ i ] ); DisplayAllCapValues( "DTWAIN_CV_ICAPGAMMA", CapOpName[i], GammaValue ); }
// Get the transfer mechanism's available for the source DTwainLongArray XferMechValues; for ( i = 0; i < 3; ++i ) { Source.GetCapValues( DTWAIN_CV_ICAPXFERMECH, XferMechValues, CapOpType[ i ] ); DisplayAllCapValues( "DTWAIN_CV_ICAPXFERMECH", CapOpName[i], XferMechValues ); }
// Get the author values available for the source DTwainStringArray Author; for ( i = 0; i < 3; ++i ) { Source.GetCapValues( DTWAIN_CV_CAPAUTHOR, Author, CapOpType[ i ] ); DisplayAllCapValues( "DTWAIN_CV_CAPAUTHOR", CapOpName[i], Author ); } }
|