Chinaunix首页 | 论坛 | 博客
  • 博客访问: 328925
  • 博文数量: 64
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 589
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-08 15:50
文章分类

全部博文(64)

文章存档

2015年(52)

2014年(3)

2013年(9)

我的朋友

分类: WINDOWS

2015-07-24 15:04:31

GetLogicalDrives函数的说明:Retrieves a bitmask representing the currently available disk drives. 
If the function succeeds, the return value is a bitmask representing the currently available disk drives. Bit position 0 (the least-significant bit) is drive A, bit position 1 is drive B, bit position 2 is drive C, and so on.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
代码:
#include <windows.h>
#include <dbt.h>
#include <stdio.h>
#include <math.h>

int main(int argc,char **argv)
{
char discPath[5],discId[5];
DWORD allDisk;
int i;
//使用GetLogicalDrives获取系统中的磁盘数量,此函数返回值是一个位图值,每一位代表一个存在的磁盘,最低位为A盘,第二位为B盘,依次类推
//如果对应位不为0,则说明盘符存在
allDisk = GetLogicalDrives();       // //返回一个32位整数,将他转换成二进制后,表示磁盘,最低位为A盘
printf("allDisk:%d\n",allDisk);
i = 0;
while(allDisk != 0){
printf("allDisk&1:%d\n",allDisk&1);
if((allDisk&1) != 0){
sprintf(discPath,"%c:\\",'C'+i);
printf("盘符:%s\n",discPath);
switch(GetDriveType(discPath)){
case DRIVE_UNKNOWN:
printf("未知类型:%s\n",discPath);
break;
case DRIVE_REMOVABLE:
printf("检测到U盘:%s\n",discPath);
sprintf(discId,"%c",'C'+i);
break;
case DRIVE_NO_ROOT_DIR:
printf("无效的路径:%s\n",discPath);
break;
case DRIVE_FIXED:
printf("本地硬盘:%s\n",discPath);
break;
case DRIVE_REMOTE:
printf("网络硬盘:%s\n",discPath);
break;
case DRIVE_CDROM:
printf("CD_ROM:%s\n",discPath);
sprintf(discId,"%c",'C'+i);
break;
case DRIVE_RAMDISK:
printf("RAM Disk:%s\n",discPath);
break;
default:
printf("default unknow\n");
break;
}
//}
}
allDisk >>= 1;
i++;
}
//}else{
// printf("allDisk failed\n");
//}
printf("end\n");
while(1){
Sleep(1000);
}
return 0;
}
阅读(4732) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~