gpt4 book ai didi

windows - 一些支持 "\Device\Xxx"格式的NT命名空间绝对路径的API

转载 作者:可可西里 更新时间:2023-11-01 09:56:52 26 4
gpt4 key购买 nike

在这份文件中, http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#paths

To make these device objects accessible by Windows applications, the device drivers create a symbolic link (symlink) in the Win32 namespace, "Global??", to their respective device objects. For example, COM0 and COM1 under the "Global??" subdirectory are simply symlinks to Serial0 and Serial1, "C:" is a symlink to HarddiskVolume1, "Physicaldrive0" is a symlink to DR0, and so on. Without a symlink, a specified device "Xxx" will not be available to any Windows application using Win32 namespace conventions as described previously. However, a handle could be opened to that device using any APIs that support the NT namespace absolute path of the format "\Device\Xxx".

API 是什么?请让我知道一些这样的功能。


例如,我们可以让一个设备位于 GLOBAL?? 命名空间中:

GLOBAL??\
COM227

我们可以使用 CreateFile 成功打开此设备:

//Note: we have to prefix it with \\.\ in order to tell CreateFile that
//we want to open something from the Global device namespace.
//Otherwise it will try to open a file
HANDLE hdev = CreateFile("\\.\COM227", GENERIC_READ, 0, null, OPEN_EXISTING, 0, 0);
if (hdev == INVALID_HANDLE_VALUE)
raise new EWin32Exception(GetLastError);

此设备(连同 Win32 Global?? 命名空间中的所有其他设备)实际上是指向“真实” 设备的符号链接(symbolic link):

GLOBAL??\
COM227 (SymbolicLink) ==> \Device\VCP0
Device\
VCP0 (Device)

所以我们尝试打开这个真实的设备:

HANDLE hdev = CreateFile("\\.\Device\VCP0", GENERIC_READ, 0, null, OPEN_EXISTING, 0, 0);
if (hdev == INVALID_HANDLE_VALUE)
raise new EWin32Exception(GetLastError);

但它失败了,错误代码为 3(系统找不到指定的文件)。

简短:

  • Works:COM227(\Device\VCP0 的别名)
  • 失败:\Device\VCP0

问题是

这意味着 CreateFile 不是 “支持\Device\Xxx 的 NT 命名空间绝对路径格式的 API”之一

However, a handle could be opened to that device using any APIs that support the NT namespace absolute path of the format "\Device\Xxx".

API 是什么

最佳答案

到目前为止提供的答案充其量只是误导。它们没有回答您的问题,也没有涵盖 NT namespace 和其他 namespace 之间的重要区别。

访问 NT 命名空间时,如果要访问只能在内核的 NT 命名空间中找到的设备,则需要使用以 Nt 开头的 API 调用,例如 NtOpenFile。例如,\Devices 中的设备在\GLOBAL?? 中没有符号链接(symbolic link)。

如果您正在访问 Win32 设备 namespace ,上述其他调用工作正常,但这些调用需要驱动程序在该 namespace 中创建符号链接(symbolic link)。

如果您想要访问仅在 NT namespace 中找到的设备,请使用 NtOpenFile .这确实是一个非常古老的 API 调用,并且已经在用户空间头文件中进进出出。它再次可用并且工作正常。

关于windows - 一些支持 "\Device\Xxx"格式的NT命名空间绝对路径的API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3546261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com