通过GUID打开设备
我正在尝试使用供应商提供的软件包访问物理设备。
在该软件包的早期版本中,他们让用户通过 DOS 符号名称打开设备:
hDevice= CreateFile("\\\\.\\DevName",
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_ExiSTING, 0, NULL);
但是,他们发布了一个新版本,要求通过 GUID 打开设备,并且在其标头中包含 DEFINE_GUID
。此更新还禁用了旧的打开设备的方法。
他们没有更新他们的文档来展示如何通过 GUID 打开设备,而且我还没有找到任何对我的 google-fu 有帮助的东西。
当然一定有一个示例展示如何使用 GUID 打开设备?
I'm attempting to access a physical device using a software package from the vendor.
In earlier versions of the software package they had the user open the device via the DOS Symbolic name:
hDevice= CreateFile("\\\\.\\DevName",
GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_ExiSTING, 0, NULL);
However, they released a new version which requires the device be opened by GUID and a DEFINE_GUID
is included in their header. This update also disabled the old method to open the device.
They did not update their documentation to show how to open the device by GUID and I haven't been able to find anything helpful with my google-fu.
Surely there must be an example somewhere showing how to open a device using the GUID?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
供应商很可能为您提供了“设备接口 GUID”。
要获取可用于
CreateFile()
的名称,您必须枚举具有该 GUID 的所有设备。这是通过使用标志DIGCF_DEVICEINTERFACE
调用SetupDiGetClassDevs()
来完成的。结果列表由设备信息集(HDEVINFO)的句柄表示。然后,您将该句柄输入到对SetupDiEnumDeviceInterfaces()
的重复调用中以遍历列表。对于每个列表项,您必须调用SetupDiGetDeviceInterfaceDetail()
来接收相应的设备路径。Most likely the vendor gave you a 'device interface GUID'.
To get a name that you can use for
CreateFile()
, you have to enumerate all devices with that GUID. This is done by callingSetupDiGetClassDevs()
with the flagDIGCF_DEVICEINTERFACE
. The resulting list is represented by a handle to a device information set (a HDEVINFO). Then you feed that handle into repeated calls toSetupDiEnumDeviceInterfaces()
to walk the list. For each list item you then have to callSetupDiGetDeviceInterfaceDetail()
to receive the corresponding device path.您现在可能已经明白了,但是 WinObj 对于戳戳来说非常方便围绕对象管理器命名空间。一旦您在那里找到了要查找的对象的名称,就可以非常简单地打开它。
You've probably figured it out by now, but WinObj is pretty handy for poking around the object manager namespace. Once you find the name of the object you're looking for there, it should be pretty straightforward to get the open right.