DTWAIN_ArrayGetAtString

Top  Previous  Next

The DTWAIN_ArrayGetAtString function retrieves a string value from a DTWAIN_ARRAY.

 

DTWAIN_BOOL DTWAIN_ArrayGetAtString (

DTWAIN_ARRAY

Array,

LONG

Index,

LPTSTR

pValue );

 

Parameters

Array

DTWAIN_ARRAY that the value will be retrieved from.

 

Position

Index of value to retrieve.

 

pValue

Pointer to the character buffer that will receive the value.

 

Return Values

If the function succeeds, TRUE is returned.  If the function fails FALSE is returned.

 

Character specific version

ANSI version:

DTWAIN_ArrayGetAtStringA

Unicode version:

DTWAIN_ArrayGetAtStringW

 

Comments

DTWAIN_ArrayGetAtString is a specialized version of DTWAIN_ArrayGetAt.

 

The DTWAIN_ArrayGetAtString function copies the string located at index Index to the address pValue.   A DTWAIN_ARRAY is indexed starting from position 0 through position n-1, where n is the total number of items in the DTWAIN_ARRAY Array.

 

Note that pValue must point to a character buffer that has a length greater or equal to the length of the string that is retrieved, with also room for the terminating null character..  To ensure that the buffer is sized correctly, call DTWAIN_ArrayGetStringLength to get the number of characters:

 

Below is a small C++ code example of ensuring that strings are retrieved correctly from a buffer.

 

   #include <tchar.h>        

  //...

   DTWAIN_ARRAY sArray;

    // create the array

   sArray = DTWAIN_ArrayCreate( DTWAIN_ARRAYSTRING, 1);

 

   // set a string at the first element

  DTWAIN_ArraySetAtString( sArray, 0, _T("This is a string"));

 

   // get the length of the string

   LONG sLen = DTWAIN_ArrayGetStringLength( sArray, 0 );

 

   // create a dynamic string using new[].  Make sure we have room for the NULL terminator */

   LPTSTR pBuffer = new TCHAR[ sLen + 1 ];

 

   // get the string

   DTWAIN_ArrayGetAtString( sArray, 0, pBuffer );

 

 

Other languages should also make the appropriate provisions provided by the language to ensure that the buffer passed to DTWAIN_ArrayGetAtString is large enough to hold the string, plus the ending null terminator.  If this is not done, the application may crash or experience erratic behavior.

 

This function will only work for DTWAIN_ARRAY's that can store string values (i.e. the DTWAIN_ARRAY was created with the DTWAIN_ARRAYSTRING style. See DTWAIN_ArrayCreate for more information).

 

TWAIN State Transitions

None.

 

Prerequisite Function Call(s)

DTWAIN_SysInitialize

 

See Also

Retrieving Values from a DTWAIN_ARRAY