获取磁盘的 总容量,空余容量,已用容量 【windows】
2024-08-31 07:00:52
使用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,而有时不是。
最新文章
- android 权限大全
- Linux的硬链接为何不能链接目录
- A^B问题
- 无聊之作,RPGdemo制作(一)角色state模式
- openmp 并行求完数
- using System.Reflection;
- poj -2975 Nim
- ORM-Dapper+DapperExtensions
- WPF制作带明细的环形图标
- JavaNIO深入学习
- IdentityServer4 记录
- Vagrant 入门指南
- python---反射详解
- 阿里云Https通配符证书购买
- leveldb源码分析--Comparator
- mybatis源码-解析配置文件(二)之解析的流程
- android 开发 ANR
- Go语言的类型转换和类型断言
- 常量池之字符串常量池String.intern()
- matplotlib —— 添加文本信息(text)