学习API 判断光驱是否为光盘

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#define BUFSIZE 512

int main(int argc,PCHAR argv[])
{
CHAR szFileSystemNameBuffer[BUFSIZE];
DWORD dwLastError;
DWORD dwFileSystemFlags;
if (argc != 2)
{
printf("请输入驱动器的根路径,比如:\"D:\\\"\n");
return -1;
}
if (GetDriveType(argv[1]) != DRIVE_CDROM)
{
printf("驱动器 %s 不是CD/DVD ROM。\n",argv[1]);
return -1;
}
if (!GetVolumeInformation(
argv[1],NULL,0,
NULL,NULL,
&dwFileSystemFlags,
szFileSystemNameBuffer,
BUFSIZE))
{
dwLastError = GetLastError();
if (dwLastError == 21)
{
printf("设备未就绪,请放入光盘!\n");
return 0;
}
else
{
printf("GetVolumeInfomation 错误 %d\n",dwLastError);
return 0;
}
printf("光盘已放入,文件系统类别 %s。\n",szFileSystemNameBuffer);
return 0;
}
}

运行可是 *.exe C:\

posted @ 2016-05-05 15:57  mousemin  阅读(258)  评论(0编辑  收藏  举报