windows 如何在 Visual C++ 中列出所有连接的 USB 设备
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2735920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to list all attached USB devices in Visual C++
提问by vinzenzweber
In Short:I need to detect hotplug events of my USB CDC device by PID/VID and get the corresponding virtual COM port which was created by Windows in Visual C++ and in the end create a dll.
简而言之:我需要通过 PID/VID 检测我的 USB CDC 设备的热插拔事件,并获取由 Windows 在 Visual C++ 中创建的相应虚拟 COM 端口,最后创建一个 dll。
I have a USB CDC device which I need to be notified of when connected/disconnected on Windows. My approach is to use RegisterDeviceNotification
and an "invisible" Window to receive WM_DEVICECHANGE
notifications. This part is working so far.
我有一个 USB CDC 设备,在 Windows 上连接/断开连接时需要通知我。我的方法是使用RegisterDeviceNotification
“隐形”窗口来接收WM_DEVICECHANGE
通知。到目前为止,这部分正在工作。
Now as far as I found out I need to get the list of USB devices that is plugged, iterate over it and filter out the devices with my PID/VID? I assume that I am then able to get more informations about the device including the COM port?
现在据我所知,我需要获取插入的 USB 设备列表,对其进行迭代并用我的 PID/VID 过滤掉设备?我假设我然后能够获得有关设备的更多信息,包括 COM 端口?
Is the only way to achieve my goal to use SetupDi
calls in setupapi.h
? Is using WDK / DDK the only way to achieve my goal?
是实现我使用SetupDi
调用目标的唯一方法setupapi.h
吗?使用 WDK / DDK 是实现我的目标的唯一方法吗?
As soon as that is working I open-source it on http://github.com/vinzenzweber/USBEventHandler. The Mac version is available already!
一旦它起作用,我就在http://github.com/vinzenzweber/USBEventHandler上将其开源。Mac 版本已经可用!
回答by vinzenzweber
After digging through tons of useless documentation at msdn and some debugging I found the missing link: SetupDi calls in setupapi.h: More infos as well as source code for Mac and Windows can be found in my USBEventHandler project at github.comwith sources for Mac and Windows.
在 msdn 上挖掘了大量无用的文档并进行了一些调试后,我找到了缺失的链接: setupapi.h 中的 SetupDi 调用:更多信息以及 Mac 和 Windows 的源代码可以在 github.com 的 USBEventHandler 项目中找到,其中包含以下源代码Mac 和 Windows。