How can I detect when an SD card is plugged in?

青春壹個敷衍的年華 提交于 2020-01-10 03:05:09

问题


I'm writing a PC application in C++ that needs to detect when a user connects an SD card to his/her computer. I know how to detect when the card reader is connected, but I do not know how to detect when individual cards are connected/removed.

Does Windows have an IO interface to detect arrival/removal of SD cards?

[Update] the WM_DEVICECHANGE technique that was suggested works only for detecting when an SD Card reader is plugged in. It does not detect when individual cards are inserted into the card reader.


回答1:


Think this is what you need:

http://www.codeproject.com/KB/dotnet/devicevolumemonitor.aspx




回答2:


check the messages from WM_DEVICECHANGE here is an example




回答3:


WM_DEVICECHANGE might be your answer. Here is an example with CDROM.




回答4:


Look at the Windows Portable Devices API, it has functionality that allows you to attach it to an SD reader (it's known as a storage device) and get events when a card is inserted or removed.

It just has two (possibly major) drawbacks:

  • It requires Windows Vista or later
  • It only has a COM API, so if you want to use it from a .NET program you either have a lot of interop ahead of you, or you have to write a wrapper in C++ or C++/CLI


来源:https://stackoverflow.com/questions/583593/how-can-i-detect-when-an-sd-card-is-plugged-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!