DTWAIN_GetTwainNameFromConstant

DTWAIN_GetTwainNameFromConstantA

DTWAIN_GetTwainNameFromConstantW

Top  Previous  Next

The DTWAIN_GetTwainNameFromConstant function returns the string version of a TWAIN or DTWAIN constant name.

 

LONG DTWAIN_GetTwainNameFromConstant (

LONG

ConstantCategory

LONG

ConstantValue

LPTSTR

szBuffer

LONG

Maxlen );

 

Parameters

 

ConstantCategory

The category of TWAIN or DTWAIN constant to search (see DTWAIN TWAIN name constants)

 

ConstantValue

The value of the TWAIN or DTWAIN constant.


szBuffer

Specifies the address of the character buffer to store the string version of the constant name, or NULL


MaxLen

Specifies the maximum number of characters to copy to szBuffer.

 

 

Return Values

If the function succeeds, the number of characters copied to szBuffer is returned.  If the function fails, DTWAIN_FAILURE1 is returned.

 

Character specific version

ANSI version:

DTWAIN_GetTwainNameFromConstantA

Unicode version:

DTWAIN_GetTwainNameFromConstantW

 

Comments

The DTWAIN_GetTwainNameFromConstant function is a utility function that returns a stringized version of a TWAIN or DTWAIN constant value.  


The ConstantCategory will be an integer denoting the category of the constant that will be converted to a string.  The category value basically sets which "table" to look for the constant value ConstantValue.


The szBuffer will, on return, contain the string version of the TWAIN or DTWAIN constant.  If szBuffer is NULL, then no characters are copied, however the return value will still reflect the number of characters that would be needed to store the string.


The MaxLen is the maximum length of szBuffer, which must include room for the terminating NULL character.  If szBuffer is NULL, the MaxLen argument is ignored.


A small C/C++ example of usage of DTWAIN_GetTwainNameFromConstant:


DTWAIN_SOURCE source;

source = DTWAIN_SelectSource();

if ( source )

{

    // Get all of the supported pixel types

    DTWAIN_ARRAY aPixelTypes;

    DTWAIN_EnumPixelTypes(source, &aPixelTypes); 

    // an alternative to the above is aPixelTypes = DTWAIN_ArrayGetCapValues(source, ICAP_PIXELTYPE, DTWAIN_CAPGET);


    LONG arrayCount = DTWAIN_ArrayGetCount( aPixelTypes );

    char szBuffer[100];

    for (LONG i = 0; i < arrayCount; ++i )

    {

        // Get the i'th value in the array

        LONG value;

        DTWAIN_ArrayGetAtLong (arrayCount, i, &value);


        // We want to print all of the TWPT_* names that match each pixel type found

        DTWAIN_GetTwainNameFromConsant( DTWAIN_CONSTANT_TWPT, value, szBuffer, 100);

        printf ("The pixel type supported is %s\n", szBuffer);  // This will print "TWPT_BW", "TWPT_RGB", etc. depending on value

   }

   DTWAIN_ArrayDestroy( aPixelTypes );

}


The reason why a category (the first parameter) is required is that many TWAIN and DTWAIN constant values happen to share the same value.  Thus to disambiguate these value clashes, a category needs to be determined -- the first argument denotes this category.


Note that the constant category names start with DTWAIN_CONSTANT_, and then 3 or more characters denoting the exact category of names to search.  Most of these categories will require you to know what names you wish to stringize.  For example, DTWAIN_CONSTANT_TWAL will select the "CAP_ALARMS" category of constants, which would be "TWAL_ALARM", "TWAL_FEEDERERROR", etc.

 

TWAIN State Transitions

None.

 

Prerequisite Function Call(s)

DTWAIN_SysInitialize