检测SD卡硬件的驱动器号 [英] Detect drive letter of SD card hardware

查看:186
本文介绍了检测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.

推荐答案

您可以尝试

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卡硬件的驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆