检测SD卡硬件的驱动器字母

4

有没有一种程序化的方法可以在Windows上检测SD卡的驱动器号?这种方法是否支持内部和外部SD卡硬件?感谢您的时间。

1个回答

1
你可以尝试使用 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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接