有没有办法在 Windows 上以编程方式检测 SD 卡的驱动程序盘符?该方法是否支持内部和外部 SD 卡硬件?感谢您的宝贵时间。
最佳答案
你可以试试GetLogicalDriveStrings获取驱动器号,然后使用 GetDriveType查看驱动器是否可移动。然后你可以获得更多这样的设备信息(示例是针对 cd-rom 但应该向你展示这个想法):
//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);
关于c++ - 检测SD卡硬件盘符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3462264/