Example: Getting Device Capabilities

Top  Previous  Next

The example below gets the current device capability setting for DTWAIN_CV_ICAPBRIGHTNESS (the brightness setting).  This example assumes that DTWAIN_SysInitialize has been called successfully.

 

 

#include <dtwain.h>

#include <tchar.h>

 

/* Get the brightness */

void GetBrightness( )

{

  DTWAIN_ARRAY  Brightness;

  DTWAIN_FLOAT BrightVal;

  DTWAIN_BOOL bOk;

  DTWAIN_SOURCE SelectedSource;

 

   /* Select the Source.  Return if none selected */

   SelectedSource = DTWAIN_SelectSource( );

   if ( !SelectedSource)

        return;

 

   /* Now call function to set the capability */

   bOk = DTWAIN_GetCapValues(SelectedSource,

                                                                        DTWAIN_CV_ICAPBRIGHTNESS,

                                                                        DTWAIN_CAPGETCURRENT,

                                                                       &Brightness);

 

   /* Check if capability failed to set */

   if ( bOk == FALSE )

      MessageBox(NULL, _T("Sorry.  Capability could not be set"), _T("Error"), MB_ICONSTOP);

   else

 

       /* Retrieve the brightness setting from the array */

      DTWAIN_ArrayGetAtFloat(Brightness, 0, &BrightVal);

 

   /* Destroy array */

  DTWAIN_ArrayDestroy(Brightness);

  DTWAIN_CloseSource( SelectedSource );

}

 

The example below gets the device capability for DTWAIN_CV_ICAPFRAMES  If so, it sets the capability using the DTWAIN_FRAME type as the data.  If you want to know how to set the TW_FRAME type, this example shows this in action.  Note the use of DTWAIN_ArraySetAt instead of DTWAIN_ArrayAdd.

 

#include <dtwain.h>

void GetFrameValues()

{

  DTWAIN_FRAME Frame;

  DTWAIN_BOOL bOk;

  DTWAIN_SOURCE SelectedSource;

  DTWAIN_ARRAY FrameArray;

 

   /* Select the Source.  Return if none selected */

   SelectedSource = DTWAIN_SelectSource();

   if ( !SelectedSource)

       return;

 

   /* Now call function to set the capability */

   bOk = DTWAIN_GetCapValues(SelectedSource,

                                                                        DTWAIN_CV_ICAPFRAMES,

                                                                        DTWAIN_CAPGETDEFAULT,

                                                                       &FrameArray);

 

   /* Check if capability failed to set */

   if ( bOk == FALSE )

      MessageBox(NULL, _T("Sorry.  Capability could not be set"), _T("Error"), MB_ICONSTOP);

   else

 

       /* Retrieve the frame setting */

      DTWAIN_ArrayGetAt(FrameArray, 0, &Frame);

 

 

   /* Destroy array */

  DTWAIN_ArrayDestroy(FrameArray);

  DTWAIN_CloseSource( SelectedSource );

}

 

 

The example below gets the device capability for DTWAIN_CV_ICAPXRESOLUTIONS. Note that a test to see if the returned array type from DTWAIN_GetCapValues is DTWAIN_CONTRANGE, DTWAIN_CONTENUMERATION or a DTWAIN_CONTONEVALUE

 

#include <dtwain.h>

void GetMultiCapValues()

{

  DTWAIN_ARRAY  Resolutions;

  DTWAIN_BOOL bOk;

  DTWAIN_SOURCE SelectedSource;

  double ResolutionValue;

   LONG Container;

 

   /* Select the Source.  Return if none selected */

   SelectedSource = DTWAIN_SelectSource();

   if ( !SelectedSource)                

       return;

 

   /* Now call function to set the capability */

   bOk = DTWAIN_GetCapValues(SelectedSource,

                                                                         DTWAIN_CV_ICAPXRESOLUTION,

                                                                         DTWAIN_CAPGET, &Resolutions);

   /* Return if there was a problem */

   if ( !bOk)

       return;

 

   /* Check if TW_RANGE is the container type */

   /* See if the container type for DTWAIN_CAPGET is a DTWAIN_CONTRANGE */

   Container = DTWAIN_GetCapContainer(Source,

                                                                   DTWAIN_CV_ICAPXRESOLUTION,

                                                                                          DTWAIN_CAPGET);

 

   if ( Container == DTWAIN_CONTRANGE )

 

       DTWAIN_FLOAT MinVal, MaxVal, StepVal, DefaultVal, CurrentVal;

       /* The Resolutions is a DTWAIN_RANGE

           Any DTWAIN_RANGE function can be applied to Resolutions*/

      DTWAIN_RangeGetAll(Resolutions, &MinVal, &MaxVal,

                                                         &StepVal, &DefaultVal, &CurrentVal);

 

   else

   {

       LONG index;

      /* Container is a TW_ENUMERATION or TW_ONEVALUE */

      /* Get the number of resolution values returned */

      LONG Count = DTWAIN_ArrayGetCount(Resolutions);

 

      /* Get each value in the array

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

   

           /* This gets the resolution value located at Resolutions[index] */

          DTWAIN_ArrayGetAtFloat(Resolutions, index, &ResolutionValue);

     }    

 

 

   /* Destroy array */

  DTWAIN_ArrayDestroy(Resolutions);

  DTWAIN_CloseSource( SelectedSource );

}