XBase++ Floating Point DTWAIN Examples

Top  Previous  Next

Here are some examples of usage of XBase++ and handling of floating point in DTWAIN:

 

Example : Set the current resolution value:

 

#include "Dll.ch"

#include "DTWAIN32.CH"

 

PROCEDURE Main

  LOCAL TwainSource, nDLLHandle, res, returnValue

  LOCAL retStr := Space(254)

 

  /* Load the DTWAIN DLL */

  nDLLHandle := DllLoad( "DTWAIN32.DLL" )

 

  /* Initialize DTWAIN */

  DLLCall (nDLLHandle,DLL_STDCALL, "DTWAIN_SysInitialize")

 

  /* Get a TWAIN Source from Select Source Dialog */

  TwainSource := DLLCall(nDLLHandle,DLL_STDCALL, "DTWAIN_SelectSource")

 

  /* If user selected a source, attempt to set the resolution to 300 */

  IF  TwainSource <> 0

      returnValue := DLLCall(nDLLHandle,DLL_STDCALL,"DTWAIN_SetResolutionString", TwainSource, "300.0")

      IF returnValue <> 0

          /* Resolution set successfully */

          DLLCall(nDLLHandle, DLL_STDCALL, "DTWAIN_GetResolutionString", TwainSource, @retStr)

      ENDIF

  ENDIF

 

  /* Uninitialize DTWAIN and unload the DLL */

  DLLCall(nDLLHandle,DLL_STDCALL,"DTWAIN_SysDestroy")

 

  DllUnload( nDLLHandle )

 

RETURN

 


 

In the above example, the function DTWAIN_SetResolutionString and DTWAIN_GetResolutionString act exactly the same as DTWAIN_SetResolution and DTWAIN_GetResolution, with the lone exception being that the last parameter of the DTWAIN_xxxString() function is a string value instead of a DTWAIN_FLOAT.  This allows XBase++ programmers to use string values instead of floating point variables that may not be compatible to Windows 64-bit types.

 

Please note:

There are functions named F2Bin( ) and Bin2F( ) defined for XBase++.  However with our experience using these functions, the floating point values passed to the DTWAIN functions do not convert to proper IEEE 64-bit values that adhere to the same layout that C or C++ expects.  Therefore it is best to have DTWAIN functions interpret the values in a safe, sure way, and that is to use the string versions of the DTWAIN functions that require floating point data.