DrgQueryStrNameLen - Example Code

This example shows how to obtain the length of a string given that the string handle is known. The string handle must have been originally created with the DrgAddStrHandle function.

#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);


[Back: DrgQueryStrNameLen - Related Functions]
[Next: DrgQueryStrNameLen - Topics]