c++,Windows 7:识别 USB 拇指驱动器已连接并识别 USB 标识符?
我想编写一个软件,当 USB 拇指驱动器连接到 USB 端口时,它会自动将一些文件复制到 USB 拇指驱动器上。为此,我想知道:
如何编写一个在连接 USB 拇指驱动器时收到通知的 C++ 应用程序?
有什么方法可以识别 USB 拇指驱动器,以便我可以跟踪是否已插入新的 USB 拇指驱动器?
I'd like to write a software that automatically copies some files onto a usb thumbdrive when it gets connected to the usb port. for this i would like to know:
how can I write a c++ application that gets notified when a usb thumbdrive gets connected?
is there any way to identify the usb thumbdrive, so that i can keep track off whether or not a new usb thumbdrive was inserted already?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您可以使用 WM_DEVICECHANGE 窗口消息在系统插入或删除设备时收到通知,这里是进一步阅读的链接 http://msdn.microsoft.com/en-us/library/windows/desktop/aa363480%28v=vs.85%29.aspx
i think you can use the WM_DEVICECHANGE window message to be notified when a device is inserted or removed from the system, here is a link for further reading http://msdn.microsoft.com/en-us/library/windows/desktop/aa363480%28v=vs.85%29.aspx
克里斯特的回答涵盖了基础知识。他没有提到的是如何做(2),识别它。您正在寻找
DBT_DEVTYP_DEVICEINTERFACE
< /a> 到达事件。此事件包含一个dbcc_name
,它标识确切的设备。 (前提是该设备符合 USB 规范并具有唯一的序列号;不要指望廉价的中国设备会这样做。)Krister's answer covers the basics. What he doesn't metion is how to do (2), idenifying it. You're looking for the
DBT_DEVTYP_DEVICEINTERFACE
arrival event. This event contains adbcc_name
, which is identifies the exact device. (Provided that the device adheres to the USB specification and has a unique serial number; don't expect cheap Chinese devices to.)