DrgQueryStrNameLen
Appearance
This function gets the length of a string associated with a string handle.
Syntax
DrgQueryStrNameLen(hstr)
Parameters
- hstr (HSTR) - input
- String handle. The handle must be created with DrgAddStrHandle.
Returns
- cLength (ULONG) - returns
- Length of the string associated with hstr.
- 0 - The string handle is NULLHANDLE or is not valid.
- Other - The length of the string associated with the string handle, excluding the null terminating byte.
Remarks
This function should be called before calling the DrgQueryStrName function. It is used to determine and allocate the buffer size for the string associated with the string handle. If the input string handle is NULLHANDLE or not valid, a length of 0 is returned.
Errors
Possible returns from WinGetLastError:
- PMERR_INVALID_PARAMETERS (0x1208)
- An application parameter value is invalid for its converted PM type. For example: a 4-byte value outside the range -32 768 to +32 767 cannot be converted to a SHORT, and a negative number cannot be converted to a ULONG or USHORT.
Example Code
#define INCL_WINSTDDRAG /* Direct Manipulation (Drag) Functions */ #define INCL_DOSMEMMGR /* Memory Management Functions for */ /* DosAllocMem */ #include <OS2.H> HSTR hstr; /* Handle to a string. The handle must */ /* have been created with */ /* DrgAddStrHandle. */ PSZ pBuffer; /* Buffer where the null-terminated */ /* string is returned */ ULONG ulStrlen; /* String length */ ULONG ulBytesRead;/* Number of bytes read */ ULONG rc; /* Return code */ ulStrlen = DrgQueryStrNameLen(hstr) + 1; rc = DosAllocMem((PVOID *) pBuffer, (LONG)ulStrlen, fPERM | PAG_COMMIT); /*****************************************************************/ /* The ulBytesRead parameter contains the number of bytes */ /* actually written to the memory pointed to by pBuffer */ /*****************************************************************/ ulBytesRead = DrgQueryStrName(hstr, ulStrlen, /* Number of bytes to copy */ pBuffer);