【问题标题】:List the content of the Win32 device namespace列出 Win32 设备命名空间的内容
【发布时间】:2016-07-11 23:30:03
【问题描述】:

来自 microsoft-doku:

"\\.\" 前缀将访问 Win32 设备命名空间,而不是 Win32 文件命名空间。这是如何访问物理磁盘和 卷是直接完成的,不经过文件 系统,如果 API 支持这种类型的访问。您可以访问许多 磁盘以外的设备以这种方式(使用 CreateFile 和 例如,DefineDosDevice 函数)。

例如,如果要打开系统的串口通讯 端口 1,您可以在调用 CreateFile 函数时使用“COM1”。 这是有效的,因为 COM1–COM9 是 NT 中保留名称的一部分 命名空间,尽管使用 "\\.\" 前缀也适用于这些 设备名称。

我的问题是,这个命名空间中有什么可用的。是否有设备列表,我在哪里可以得到它? (我想我没有理解这个话题。当我听到设备时,我会想到目录中的某种文件。)

编辑:

好的,我会回答我自己的问题。有一个叫WinObj的软件,可以看到信息。

【问题讨论】:

  • 您可以将其发布为答案。

标签: c++ windows winapi namespaces device


【解决方案1】:

您可以使用QueryDosDevice Win32 API 调用来获取所有 Win32 设备名称。

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

顺便说一句,WinObj 主要不列出 Win32 设备名称,它列出 Windows NT 对象名称。虽然 Win32 设备名称可以在 WinObj 中的 GLOBAL?? 节点下找到。

查看https://support.microsoft.com/en-us/kb/100027中的“更多信息”

【讨论】:

    【解决方案2】:

    好的,我会回答我自己的问题。有一个叫WinObj的软件,可以看到信息。

    【讨论】:

      猜你喜欢
      • 2019-06-26
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      • 2011-04-26
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多