DosQueryHType enables an application to determine whether a handle is to a file, a pipe, or a device. This function can be used when a file-oriented application needs to modify its behavior, depending on the source of its input. For example, CMD.EXE suppresses writing prompts when its input is from a disk file.

The following code fragment determines whether a given file handle refers to a file or a device. Assume that the desired file handle has been placed into FileHandle already.

    #define INCL_DOSFILEMGR   /* File system values                 */
    #include <os2.h>
    #include <stdio.h>

    HFILE   hfFileHandle;    /* File handle                        */
    ULONG   ulHandType;      /* Handle type (returned)             */
    ULONG   ulFlagWord;      /* Device driver attribute (returned) */
    APIRET  ulrc;            /* Return code                        */

    ulrc = DosQueryHType(hfFileHandle,
                         &ulHandType,
                         &ulFlagWord);

    if (ulrc != 0) {
        printf("DosQueryHType error: return code = %ld",
               ulrc);
        return;
    }

In the preceding example, DosQueryHType returns a value that characterizes the type of file handle, and the associated device driver attribute word, if the handle type indicates that the file handle is associated with a local character device.


[Back] [Next]