大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 读取全部的驱动器的信息

读取全部的驱动器的信息

时间: 2021-07-31 作者:daque

作家:宁静 vc6.0 w2k编写翻译经过 这类小步调,能用的场合很多.以是就写一个完备的代码 给大师参考参考 #include "stdafx.h" #include  <iostream.h> const dword maxlen = 100; void showdriveinfo(lptstr drive) { //输入摆设典型 uint result; result = getdrivetype(drive); if (result == drive_removable) cout << "可挪动摆设" ; else if (result == drive_fixed) cout << "硬盘"; else if (result == drive_remote) cout << "搜集启动器" ; else if (result == drive_cdrom ) cout << " 光驱"; else if (result == drive_ramdisk) cout << "ram disk"; else if (result == drive_unknown) cout << "未知的摆设"; else return; cout << '\t'; //给出空间消息 unsigned __int64 i64freebytestocaller; unsigned __int64 i64totalbytes; unsigned __int64 i64freebytes; dword dwsectperclust; dword dwbytespersect; dword dwfreeclusters; dword dwtotalclusters; dword temptotal; dword tempfree; bool fresult; typedef dword (winapi * getdiskfreespaceex)(lpctstr , pularge_integer , pularge_integer , pularge_integer ); getdiskfreespaceex pgetdiskfreespaceex; pgetdiskfreespaceex = (getdiskfreespaceex)getprocaddress( getmodulehandle("kernel32.dll"), "getdiskfreespaceexa"); if (pgetdiskfreespaceex) //即使是windows nt and windows 2000运用 getdiskfreespaceex { fresult = pgetdiskfreespaceex ( (lpctstr)drive, (pularge_integer)&i64freebytestocaller, (pularge_integer)&i64totalbytes, (pularge_integer)&i64freebytes); temptotal = i64totalbytes/1024 ; tempfree = i64freebytes/1024; } else //即使是windows 95 osr2 and windows 98 运用 getdiskfreespace { fresult = getdiskfreespace (drive, &dwsectperclust, &dwbytespersect, &dwfreeclusters, &dwtotalclusters); temptotal = dwtotalclusters*dwbytespersect*dwsectperclust/1024; tempfree = dwfreeclusters*dwsectperclust*dwbytespersect/1024; } if(fresult) { cout<<"十足磁盘含量是 "<<((float)(temptotal)/1024/1024)<<"gb\t"; cout<<"空余磁盘含量是 "<<((float)(tempfree)/1024/1024)<<"gb\t"; } cout<<endl; //像光驱,软盘,不放盘的功夫,getdiskfreespace(ex)会堕落. } void getalldrive() { int len = -1; char drive[4] ="aaa" ; lptstr lpdrivestring = new char[maxlen]; dword dwbufferlen = maxlen ; len = getlogicaldrivestrings(dwbufferlen,lpdrivestring); //博得十足的盘符 if (len < 0) cout << "操纵波折" <<endl; if (len > maxlen) cout << "buffer不及" <<endl; if (len > 0) { for (int i = 0;i < len;i = i+4) //获得的盘符有4个字符构成 a:\(null) { drive[0] = lpdrivestring[i]; //a drive[1] = lpdrivestring[i+1];//: drive[2] = lpdrivestring[i+2];// 第三个\ //drive[3] = '\0'; // 第四个为null字符 cout<<drive<<'\t'; showdriveinfo(drive); } } ///////////////////////////////////////////// //其余一种本领. /////////////////////////////////////////////// /* char d = 'a'; char drive[4]="x:\\"; for(int i = 0; i < 26;i++) { drive[0] = (char)(d+i); cout<<drive<<'\t'; showdriveinfo(drive); } */ } void main() { getalldrive(); }

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.