Andre
Andre

Reputation: 1257

List the content of the Win32 device namespace

From the microsoft-doku:

The "\\.\" prefix will access the Win32 device namespace instead of the Win32 file namespace. This is how access to physical disks and volumes is accomplished directly, without going through the file system, if the API supports this type of access. You can access many devices other than disks this way (using the CreateFile and DefineDosDevice functions, for example).

For example, if you want to open the system's serial communications port 1, you can use "COM1" in the call to the CreateFile function. This works because COM1–COM9 are part of the reserved names in the NT namespace, although using the "\\.\" prefix will also work with these device names.

My Question is, what is available in this namespace. Is there a list of devices and where can I get it ? (I think I did not understand this topic. When I hear device I think of some sort of file in a directory.)

EDIT:

Ok, I will answer my own question. There is a software called WinObj , with which one can see the information .

Upvotes: 3

Views: 2414

Answers (2)

Daniel Golding
Daniel Golding

Reputation: 420

You can use the QueryDosDevice Win32 API call to get all Win32 device names.

#include <windows.h>
#include <stdio.h>

#define DEVBUFSIZ (128 * 1024)      /* No recommended value - ~14K for me */
int main(int argc, char** argv)
{
    wchar_t devicenames[DEVBUFSIZ]  = L"";
    int     error                   = 0;
    int     wchar_count             = 0;

    wchar_count = QueryDosDeviceW(
            NULL,       /* lpDeviceName - NULL gives all */
            devicenames,
            DEVBUFSIZ);
    if (wchar_count == 0) {
        fprintf(stderr, "QueryDosDeviceW failed with error code %d\n", error);
        return 1;
    }
    for (int i = 0; i < wchar_count; i++) {
        if (devicenames[i] == '\0')
            devicenames[i] = '\n';
    }
    wprintf(L"%s", devicenames);
    return 0;
}

As an aside, WinObj does not primarily list Win32 device names, it lists Windows NT object names. Though the Win32 device names can be found under the GLOBAL?? node in WinObj.

See "More Information" in https://support.microsoft.com/en-us/kb/100027

Upvotes: 2

Andre
Andre

Reputation: 1257

Ok, I will answer my own question. There is a software called WinObj , with which one can see the information .

Upvotes: 1

Related Questions