开发者

Recognize if removable drive was inserted

开发者 https://www.devze.com 2023-03-31 04:22 出处:网络
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 che

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

精彩评论

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

关注公众号