Detect drive letter of SD card hardware(检测SD卡硬件盘符)
问题描述
有没有办法在 Windows 上以编程方式检测 SD 卡的驱动程序号?该方法是否支持内部和外部 SD 卡硬件?感谢您的宝贵时间.
Is there a way to programatically detect the driver letter of an SD card(s) on Windows? Does the method support internal and external SD card hardware? Thank you for your time.
推荐答案
你可以试试GetLogicalDriveStrings 获取驱动器号,然后使用 GetDriveType 查看驱动器是否可移动.然后您可以获得更多这样的设备信息(示例是 cd-rom,但应该向您展示这个想法):
You can try GetLogicalDriveStrings to get the drive letters and then use GetDriveType to see, whether a drive is removable or not. Then you can get more device information like this (example is for cd-rom but should show you the idea):
//handle to the drive to be examined
HANDLE hDevice = CreateFile(TEXT("\\.\G:"), //Drive to open
GENERIC_READ|GENERIC_WRITE, //Access to the drive
FILE_SHARE_READ|FILE_SHARE_WRITE, //Share mode
NULL, //Security
OPEN_EXISTING,0, // no file attributes
NULL);
if (hDevice == INVALID_HANDLE_VALUE) return 0;
CDROM_TOC val; // table of contents for a generic CDROM
DWORD nBytesReturned;
BOOL bResult= DeviceIoControl(
hDevice,
IOCTL_CDROM_READ_TOC,//operation to perform
&val, sizeof(val),//no input buffer
&val, sizeof(val),//output buffer
&nBytesReturned,//#bytes returned
(LPOVERLAPPED) NULL);//synchronous I/O
CloseHandle(hDevice);
这篇关于检测SD卡硬件盘符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测SD卡硬件盘符
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- c++ STL设置差异 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
