Detect drive letter of SD card hardware

时光怂恿深爱的人放手 提交于 2019-12-23 12:27:03

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/3462264/detect-drive-letter-of-sd-card-hardware

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