Guest User

diskspace

a guest
Jun 27th, 2025
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. /* problem domain to decompose:
  2. info program that displays CPU information and RAM, disk management
  3. CPU - temperature, different cores maybe, */
  4.  
  5. // all errors enabled, so do this to minimise window error warnings that I cannot control
  6. #pragma warning(push, 0)
  7. #pragma warning (disable : 4668)
  8. #include <windows.h>
  9. #pragma warning(pop)
  10.  
  11. #include <stdbool.h>
  12. #include <stdio.h>
  13.  
  14.  
  15.  
  16. int main(void)
  17. {
  18. // declare variables to pass into disk space function
  19. ULARGE_INTEGER FreeBytesToCaller;
  20. ULARGE_INTEGER TotalBytes;
  21. ULARGE_INTEGER TotalFreeBytes;
  22.  
  23. // declare variable to hold the calculation to convert bytes to gibabytes
  24. ULARGE_INTEGER BytesToGB;
  25. BytesToGB.QuadPart = 1024 * 1024 * 1024;
  26.  
  27. // call function to retreive disk space information
  28. bool DiskResult = GetDiskFreeSpaceExA(0, &FreeBytesToCaller, &TotalBytes, &TotalFreeBytes);
  29.  
  30. // variables to hold result of conversion calculation
  31. ULARGE_INTEGER GBTotal;
  32. ULARGE_INTEGER TB;
  33. ULARGE_INTEGER GBTotalFreeBytes;
  34.  
  35. // QuadPart that holds the actual 64 bit integer. Need to do this for maths operations
  36. // calculations
  37. GBTotal.QuadPart = TotalBytes.QuadPart / BytesToGB.QuadPart;
  38. GBTotal.QuadPart = GBTotal.QuadPart % 1000;
  39. TB.QuadPart = TotalBytes.QuadPart / (BytesToGB.QuadPart * 1024);
  40. GBTotalFreeBytes.QuadPart = TotalFreeBytes.QuadPart / BytesToGB.QuadPart;
  41.  
  42. if (DiskResult != 0)
  43. {
  44. // print out info for D drive
  45. printf("Total size on disk (D:): %llu.%llu TB\n", TB.QuadPart, GBTotal.QuadPart);
  46. printf("Total free space (D:): %llu GB\n", GBTotalFreeBytes.QuadPart);
  47. printf("Heloo\n");
  48.  
  49. }
  50. else
  51. {
  52. OutputDebugStringA("DiskResult failed!\n");
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment