Floating Point Issues and DTWAIN

Top  Previous  Next

For floating point parameters  DTWAIN relies on the DTWAIN_FLOAT, or 64-bit IEEE floating point type (this is equivalent to a double in C or C++). 


Most languages support this type, however for some languages (examples are XBase++ from Alaska Software, or a scripting language such as Macro Scheduler), this type is minimally supported and/or the programmer will have difficulty getting the language to support this type.  This issue is evident if a log of the DTWAIN function is inspected, and instead of the floating point value being passed to the function, a garbage or totally wrong floating point number is passed to the DTWAIN function.

 

For this situation, DTWAIN has alternate functions to set and get floating point values, as well as set/get functions that requires usage of the DTWAIN_ARRAY's that hold DTWAIN_FLOAT types.  These functions are as follows:


DTWAIN_ArrayANSIStringToFloat

DTWAIN_ArrayFindFloatString

DTWAIN_ArrayFloatToANSIString

DTWAIN_ArrayFloatToString

DTWAIN_ArrayFloatToWideString

DTWAIN_ArrayGetAtFloatString

DTWAIN_ArrayGetAtFrameString

DTWAIN_ArrayInsertAtFloatString

DTWAIN_ArrayInsertAtFloatStringN

DTWAIN_ArraySetAtFrameString

DTWAIN_ArrayStringToFloat

DTWAIN_ArrayWideStringToFloat

DTWAIN_FrameCreateString

DTWAIN_FrameGetAllString

DTWAIN_FrameGetValueString

DTWAIN_FrameSetAllString

DTWAIN_FrameSetValueString

DTWAIN_GetAcquireArea2String

DTWAIN_GetBrightnessString

DTWAIN_GetContrastString

DTWAIN_GetImageInfoString

DTWAIN_GetResolutionString

DTWAIN_GetRotationString

DTWAIN_RangeGetExpValueFloatString

DTWAIN_RangeGetNearestValueFloatString

DTWAIN_RangeGetValueFloatString

DTWAIN_RangeSetAllFloatString

DTWAIN_RangeSetValueFloatString

DTWAIN_SetAcquireArea2String

DTWAIN_SetAcquireImageScaleString

DTWAIN_SetBlankPageDetectionString

DTWAIN_SetBrightnessString

DTWAIN_SetContrastString

DTWAIN_SetPDFPageScaleString

DTWAIN_SetPDFPageSizeString

DTWAIN_SetPDFTextElementFloatString

DTWAIN_SetResolutionString

DTWAIN_SetRotationString

DTWAIN_IsDIBBlankString

 

All of these functions substitute the DTWAIN_FLOAT parameter with an LPCTSTR or LPTSTR parameter.  Since almost every (if not every) computer language that is available on the Windows platform handles strings with no issues, it is recommended to use the functions above to set or get floating point values.


The strings must represent a valid, floating point value that is C-compatible.  For example:


"11.0"

"0.234"

"234"

"1.0e10"


are valid floating point strings.  The last one, "1.0e10" uses scientific notation.

 

Here is a small 'C' example of using the array transformation functions (note that this example never needs to be done using 'C', since 'C' handles DTWAIN_FLOAT values with no issues.  The example is only for illustrative purposes):

 

 #include "dtwain.h"

 #include <stdio.h>

 

  void Test()

  {

      DTWAIN_SOURCE TwainSource;

      DTWAIN_SysInitialize( );

      TwainSource = DTWAIN_SelectSource( );

      if ( TwainSource )

      {

            LONG i, Whole, Frac, numValues;

            double dVal;

            DTWAIN_ARRAY floatArray, strArray;

 

            /* get the resolution values that are used by the Source */

            /* These values are stored as DTWAIN_FLOAT

            DTWAIN_EnumResolutionValues( TwainSource, &floatArray, TRUE );

 

            /* Convert to DTWAIN_FLOAT array to string DTWAIN_ARRAY */

            strArray = DTWAIN_ArrayFloatToANSIString( floatArray );

            numValues = DTWAIN_ArrayGetCount( strArray );


            for (i = 0; i < numValues; ++i )

            {

                 // Print each string value 

                 printf( "%s\n", DTWAIN_ArrayGetAtANSIStringPtr( strArray, i));

            }

       }

       DTWAIN_SysDestroy( );

 }