如何在Visual C ++中列出所有连接的USB设备 [英] How to list all attached USB devices in Visual C++

查看:165
本文介绍了如何在Visual C ++中列出所有连接的USB设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之:我需要通过PID/VID检测我的USB CDC设备的热插拔事件,并获取Windows在Visual C ++中创建的相应虚拟COM端口,最后创建一个dll.

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.

我有一个USB CDC设备,在Windows上连接/断开连接时需要通知我.我的方法是使用RegisterDeviceNotification和一个不可见"窗口来接收WM_DEVICECHANGE通知.到目前为止,这部分工作正常.

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设备的列表,对其进行遍历并使用我的PID/VID过滤掉这些设备?我以为我可以获取有关该设备的更多信息,包括COM端口?

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?

是实现我在setupapi.h中使用SetupDi调用的目标的唯一方法吗?使用WDK/DDK是实现我的目标的唯一方法吗?

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?

该方法一经运作,便在 http://github.com/vinzenzweber/USBEventHandler上开源. Mac版本已经可用!

As soon as that is working I open-source it on http://github.com/vinzenzweber/USBEventHandler. The Mac version is available already!

推荐答案

在msdn上查找了大量无用的文档并进行了一些调试后,我发现了缺少的链接:setupapi.h中的SetupDi调用:更多信息以及源代码Mac和Windows可以在我的USBEventHandler项目中找到,网址为 github.com ,其中包含Mac和Windows的源代码.

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.com with sources for Mac and Windows.

这篇关于如何在Visual C ++中列出所有连接的USB设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆