开发者

Recognize if removable drive was inserted

I have a piece of code to check the removable drives connected to the computer. But I have to check when the drive is available or inserted into the USB port.Should I write a while loop constantly checking for the drive with certain ID to become available? If I make it into a windows service, do I have to do the same i.e ke开发者_运维百科ep looping until the device is found?


Create a hidden window and use it to listen for WM_DEVICECHANGE messages.

Whatever you do, don't poll. That's horribly wasteful and inefficient.


You could use WMI (from C++ this will mean using WMI's COM API): creation events for the Win32_LogicalDisk class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜