gpt4 book ai didi

windows - 使用 CreateFile 打开设备名称

转载 作者:可可西里 更新时间:2023-11-01 12:46:48 41 4
gpt4 key购买 nike

我正在开发一个简单的设备驱动程序,我想使用 IRP 从用户模式与驱动程序进行通信。

我无法打开设备驱动程序。使用 DeviceTree我能够看到设备名称,例如\Device\MyDevice。

但是当我尝试这样打开它时:

hand := CreateFile('\Device\MyDevice', GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);  

我总是得到 INVALID_HANDLE_VALUE 并且 GetLastError 是(系统找不到指定的路径)

我做错了什么?我知道驱动程序有效,因为我可以看到它在 DebugView 中运行和打印内容。那么有什么建议吗?

enter image description here

最佳答案

这是 Tim Robinson, MVP (Windows SDK) 的一个很好的解释:

Names of the form \Device\xxx are internal NT object manager names which are inaccessible to Win32. You will only be able to access your device if it creates a symbolic link to \Device\MyDevice from the \??\ directory. Objects in the \??\ kernel directory show up through \\.\ in Win32. Use Winobj in the DDK (or download it from www.sysinternals.com) to check.

注意:如今 NT 命名空间根通过 GLOBALROOT 符号链接(symbolic link)公开,因此 Win32 可以访问任何 NT 路径,包括 \Device\xxx : 使用 \\.\GLOBALROOT\Device\xxx。在这种情况下不需要设备符号链接(symbolic link)。

关于windows - 使用 CreateFile 打开设备名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21703592/

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