枚举驱动器
//测试 含有空格的文件名, 检测, 文件名内是否有空格。
//另外就是使用 SEH异常处理
#include
#include
#include
using namespace std;
int RetDriveTypeStr(char* szTypeStr, int nType)
{
char szNoType[] = "未知类型";
char szLogical[] = "硬盘驱动器";
char szCDROM[] = "光盘驱动器";
char szRemovable[] = "移动设备"; //是否是软驱 U盘也属于
switch(nType)
{
case DRIVE_UNKNOWN:
lstrcpyn(szTypeStr, szNoType, lstrlen(szNoType)+1);
break;
case DRIVE_FIXED:
lstrcpyn(szTypeStr, szLogical, lstrlen(szLogical)+1);
break;
case DRIVE_CDROM:
lstrcpyn(szTypeStr, szCDROM, lstrlen(szCDROM)+1);
break;
case DRIVE_REMOVABLE:
lstrcpyn(szTypeStr, szRemovable, lstrlen(szRemovable)+1);
break;
default:
lstrcpyn(szTypeStr, szNoType, lstrlen(szNoType)+1);
break;
}
HANDLE hDisk = CreateFile("\\\\.\\D:",
GENERIC_READ,
FILE_SHARE_READ,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if(hDisk != INVALID_HANDLE_VALUE)
{
DISK_GEOMETRY dgDisk;
DWORD dwNotUsed = 0;
if(DeviceIoControl(hDisk,
0,
0,
0,
&dgDisk,
sizeof(dgDisk),
&dwNotUsed,
NULL))
{
if(dgDisk.MediaType == RemovableMedia)
{
cout<<"你的是移动磁盘"<