#include<windows.h>
#include <stdlib.h>
CHAR buf1[52428800]; //定义全局字符数组变量,大小50M
BOOL GetDiskSpaceInfo(LPCWSTR pszDrive){
DWORD64 qwFreeBytesToCaller, qwTotalBytes, qwFreeBytes;
BOOL bResult;
//使用GetDiskFreeSpaceEx获取磁盘信息并打印结果
bResult = GetDiskFreeSpaceEx(pszDrive,
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (bResult){
printf("使用GetDiskFreeSpaceEx获取磁盘信息\n");
printf("可获得的空闲空间(字节):\t%I64d\n", qwFreeBytesToCaller);
printf("空闲空间(字节):\t\t%I64d\n", qwFreeBytes);
printf("磁盘总容量(字节):\t\t%I64d\n", qwTotalBytes);
}
return bResult;
}
int main(int argc, PCHAR argv[]){
//GetDiskSpaceInfo(argv[2]);
int i = 0;
int a = 0;
int num_str = 0;
DWORD RSize;
DWORD64 qwFreeBytesToCaller, qwTotalBytes, qwFreeBytes;
BOOL bResult;
//使用GetDiskFreeSpaceEx获取磁盘信息并打印结果
bResult = GetDiskFreeSpaceExA("G:",
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (bResult){
printf("使用GetDiskFreeSpaceEx获取磁盘信息\n");
printf("可获得的空闲空间(字节):\t%I64d\n", qwFreeBytesToCaller);
printf("空闲空间(字节):\t\t%I64d\n", qwFreeBytes);
printf("磁盘总容量(字节):\t\t%I64d\n", qwTotalBytes);
};
printf("磁盘总容量(扇区):\t\t%I64d\n", qwTotalBytes/512);
return 0;
}
我这是截选的部分代码,问题出在最后一个printf语句,不知道为什么qwTotalBytes/512不能成功?之前的语句都正确执行了
3 个解决方案
#1
[不成功是什麽意思?輸出不符合預期?還是segment fault?,
就是这样,提示:未找到源,
就是这样,提示:未找到源,
]
#ifndef UNICODE
#define UNICODE
#endif // UNICODE
#include<stdio.h>
#include<windows.h>
#include <stdlib.h>
CHAR buf1[52428800]; //定义全局字符数组变量,大小50M
BOOL GetDiskSpaceInfo(LPCWSTR pszDrive){
DWORD64 qwFreeBytesToCaller = 0, qwTotalBytes = 0, qwFreeBytes = 0;
BOOL bResult = FALSE;
//使用GetDiskFreeSpaceEx获取磁盘信息并打印结果
bResult = GetDiskFreeSpaceEx(pszDrive,
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (bResult){
printf("使用GetDiskFreeSpaceEx获取磁盘信息\n");
printf("可获得的空闲空间(字节):\t%I64d\n", qwFreeBytesToCaller);
printf("空闲空间(字节):\t\t%I64d\n", qwFreeBytes);
printf("磁盘总容量(字节):\t\t%I64d\n", qwTotalBytes);
}
return bResult;
}
int main(int argc, PCHAR argv[]){
GetDiskSpaceInfo(L"D:");
int i = 0;
int a = 0;
int num_str = 0;
DWORD RSize = 0;
DWORD64 qwFreeBytesToCaller = 0, qwTotalBytes = 0, qwFreeBytes = 0;
BOOL bResult = FALSE;
//使用GetDiskFreeSpaceEx获取磁盘信息并打印结果
bResult = GetDiskFreeSpaceExA("C:",
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (bResult){
printf("使用GetDiskFreeSpaceEx获取磁盘信息\n");
printf("可获得的空闲空间(字节):\t%I64d\n", qwFreeBytesToCaller);
printf("空闲空间(字节):\t\t%I64d\n", qwFreeBytes);
printf("磁盘总容量(字节):\t\t%I64d\n", qwTotalBytes);
};
printf("磁盘总容量(扇区):\t\t%I64d\n", qwTotalBytes/512);
return 0;
}
#1
[不成功是什麽意思?輸出不符合預期?還是segment fault?,
就是这样,提示:未找到源,
就是这样,提示:未找到源,
]
#ifndef UNICODE
#define UNICODE
#endif // UNICODE
#include<stdio.h>
#include<windows.h>
#include <stdlib.h>
CHAR buf1[52428800]; //定义全局字符数组变量,大小50M
BOOL GetDiskSpaceInfo(LPCWSTR pszDrive){
DWORD64 qwFreeBytesToCaller = 0, qwTotalBytes = 0, qwFreeBytes = 0;
BOOL bResult = FALSE;
//使用GetDiskFreeSpaceEx获取磁盘信息并打印结果
bResult = GetDiskFreeSpaceEx(pszDrive,
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (bResult){
printf("使用GetDiskFreeSpaceEx获取磁盘信息\n");
printf("可获得的空闲空间(字节):\t%I64d\n", qwFreeBytesToCaller);
printf("空闲空间(字节):\t\t%I64d\n", qwFreeBytes);
printf("磁盘总容量(字节):\t\t%I64d\n", qwTotalBytes);
}
return bResult;
}
int main(int argc, PCHAR argv[]){
GetDiskSpaceInfo(L"D:");
int i = 0;
int a = 0;
int num_str = 0;
DWORD RSize = 0;
DWORD64 qwFreeBytesToCaller = 0, qwTotalBytes = 0, qwFreeBytes = 0;
BOOL bResult = FALSE;
//使用GetDiskFreeSpaceEx获取磁盘信息并打印结果
bResult = GetDiskFreeSpaceExA("C:",
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (bResult){
printf("使用GetDiskFreeSpaceEx获取磁盘信息\n");
printf("可获得的空闲空间(字节):\t%I64d\n", qwFreeBytesToCaller);
printf("空闲空间(字节):\t\t%I64d\n", qwFreeBytes);
printf("磁盘总容量(字节):\t\t%I64d\n", qwTotalBytes);
};
printf("磁盘总容量(扇区):\t\t%I64d\n", qwTotalBytes/512);
return 0;
}