简体   繁体   中英

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 .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM