如何确定何时将某些东西连接到我的USB端口 [英] How to find out when something is connected to my USB port

查看:168
本文介绍了如何确定何时将某些东西连接到我的USB端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我在Windows Vista中使用CODE :: BLOCKS.
我想在USB上编写一个程序,当笔驱动器或其他设备连接到USB端口时,我的程序应警告我某些设备已连接.
我想用C或C ++语言编写相同的内容.
请给我一些提示.
我想我可以从注册表中看出来.如果是,那么我想知道在连接USB驱动器之前和之后注册表项的值是什么.因为我没发现任何区别.
请帮助我.

Hello friends,
I use CODE::BLOCKS in Windows vista.
I would like to write a program on USB, that, when a pen drive or something is connected to the USB port my program should warn me that something is connected.
I would like to write the same in C or C++ language.
Please provide me some tips.
I think I can make it out from registry. If yes, then I would like to know what will be value of registry key before and after USB drive connected. Because I did not find any difference.
Please help me.

推荐答案

谢尔盖,
也许会对您有帮助:
http://www .programmersheaven.com/mb/CandCPP/352664/352664/is-it-possible-to-writeread-data-from-usb-with-cc ++/ [ http://objectmix.com/c/25806-connecting-usb-c-code.html [^ ]
http://www.dreamincode.net/forums/topic/52366 -c-project-to-writeread-usb-port/ [ http://www.edaboard.com/thread141571.html [ http://bytes.com/topic/c/answers/213150-how-chek-if-usb-port- Mounted-linux [
Hi Sergey,
maybe it will help you:
http://www.programmersheaven.com/mb/CandCPP/352664/352664/is-it-possible-to-writeread-data-from-usb-with-cc++/[^]
http://objectmix.com/c/25806-connecting-usb-c-code.html[^]
http://www.dreamincode.net/forums/topic/52366-c-project-to-writeread-usb-port/[^]
http://www.edaboard.com/thread141571.html[^]
http://bytes.com/topic/c/answers/213150-how-chek-if-usb-port-mounted-linux[^]


对于我来说,如果您希望能够进行扫描,目前还不是很清楚(在程序启动时)连接的设备,或在运行时检测 添加/删除设备的时间.如果您想检测到更改,建议您看一下此CodeProject文章:

www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-或删除 [ ^ ]

它是用C ++编写的,我发现很容易使用该代码来检测何时添加和卸下USB COM端口设备.


Soren Madsen
It is not exactly clear to me if you want to be able to scan through the connected devices (on program startup) or detect when devices are added/removed on the fly. If you want to detect the changes, I recommend taking a look at this CodeProject article:

www.codeproject.com/Articles/14500/Detecting-Hardware-Insertion-and-or-Removal[^]

It is written in C++ and I found it easy to use the code for detecting when USB COM port devices are added and removed.


Soren Madsen



以下链接可能会有所帮助:
如何使用SetupDi调用枚举硬件设备 [ MSDN:公共设备安装功能 [ http://msdn.microsoft.com/zh-CN /library/windows/hardware/ff544707(v=vs.85).aspx [
Hi
The link below might be helpful:
How to enumerate hardware devices by using SetupDi calls[^]

MSDN:Public Device Installation Functions[^]

I like using DevCon.exe in WinDDK. (Src code: WinDDK\*version\src\setup\devcon)
This should have enough info to enumerate connected devices.
http://msdn.microsoft.com/en-us/library/windows/hardware/ff544707(v=vs.85).aspx[^]

If you want to monitor the connection, you might wanna use Timer using the API above and constantly watch the changes.

Good luck,
Sean


这篇关于如何确定何时将某些东西连接到我的USB端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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