使用windows api

输入:盘符字符串

输出:磁盘容量

float get_disk_spaces(const char drive_letter, float & total_space, float & used_space)
{
BOOL fResult;
unsigned _int64 i64FreeBytesToCaller;
unsigned _int64 i64TotalBytes;
unsigned _int64 i64FreeBytes;
char dir[] = { drive_letter, ':', '\\', '\0'};
fResult = GetDiskFreeSpaceExA(
dir,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult)
{
/*QMessageBox::about(NULL, "Information",
("Get disk space " + QString(dir) + QString::number(i64TotalBytes)));*/
total_space = (float)i64TotalBytes;
used_space = (float)(i64TotalBytes - i64FreeBytes);
return (float)i64TotalBytes;
}
else
QMessageBox::about(NULL, "Information",
("Failed to get disk space " + QString(dir))); return -;
}

注意其中的字符数组 dir 一定要以'\0'结尾,否则程序时好时坏,因为有时dir末尾正好是0,而有时不是。

最新文章

  1. android 权限大全
  2. Linux的硬链接为何不能链接目录
  3. A^B问题
  4. 无聊之作,RPGdemo制作(一)角色state模式
  5. openmp 并行求完数
  6. using System.Reflection;
  7. poj -2975 Nim
  8. ORM-Dapper+DapperExtensions
  9. WPF制作带明细的环形图标
  10. JavaNIO深入学习
  11. IdentityServer4 记录
  12. Vagrant 入门指南
  13. python---反射详解
  14. 阿里云Https通配符证书购买
  15. leveldb源码分析--Comparator
  16. mybatis源码-解析配置文件(二)之解析的流程
  17. android 开发 ANR
  18. Go语言的类型转换和类型断言
  19. 常量池之字符串常量池String.intern()
  20. matplotlib —— 添加文本信息(text)

热门文章

  1. 解读windows认证
  2. Javascript/Jquery遇到字符串自动NaN的问题
  3. 听说你还搞不定java中的==和equals?
  4. Java技巧之——判断相等
  5. 002_Three.js 中添加阴影 - [Three.js] - [阴影效果]
  6. centos8系统下docker安装jenkins
  7. mac 升级到mavericks 安装php扩展现问题
  8. Mysql数据库下载
  9. django-filter的基本使用
  10. tornado的ORM