-
GetDiskFreeSpace
Can someone help me out with the GetDiskFreeSpace API?
Here is what i have and i'm getting values that don't seem correct.
Code:
unsigned long *lpSectorsPerCluster;
unsigned long *lpBytesPerSector;
unsigned long *lpNumberOfFreeClusters;
unsigned long *lpTotalNumberOfClusters;
GetDiskFreeSpace("C:", lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters);
cout << ((*lpTotalNumberOfClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100))<< " Bytes Total" << endl;
cout << ((*lpNumberOfFreeClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100)) << " Bytes Free" << endl;
thx in advance for any help
-
Re: GetDiskFreeSpace
Quote:
Originally posted by noble
Can someone help me out with the GetDiskFreeSpace API?
Here is what i have and i'm getting values that don't seem correct.
Code:
unsigned long lpSectorsPerCluster;
unsigned long lpBytesPerSector;
unsigned long lpNumberOfFreeClusters;
unsigned long lpTotalNumberOfClusters;
GetDiskFreeSpace("C:", &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, &lpTotalNumberOfClusters);
cout << ((*lpTotalNumberOfClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100))<< " Bytes Total" << endl;
cout << ((*lpNumberOfFreeClusters / 100) * (*lpSectorsPerCluster / 100) * (*lpBytesPerSector / 100)) << " Bytes Free" << endl;
The idea is that you pass a pointer to your variables, not pass the VALUE from a pointer variable you have...see my subtle changes in the variable declaration...
Argh gotta go...change the printing to avoid the dereference...
-
still seem off by a little.....
Code:
unsigned long lpSectorsPerCluster;
unsigned long lpBytesPerSector;
unsigned long lpNumberOfFreeClusters;
unsigned long lpTotalNumberOfClusters;
GetDiskFreeSpace(szDriveLetter, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters, &lpTotalNumberOfClusters);
cout << ((lpTotalNumberOfClusters / 100) * (lpSectorsPerCluster / 100) * (lpBytesPerSector / 100)) << " Bytes Total" << endl;
cout << ((lpNumberOfFreeClusters / 100) * (lpSectorsPerCluster / 100) * (lpBytesPerSector / 100)) << " Bytes Free" << endl;
-
GetDiskFreeSpaceEx will be simpler to use. It was designed to replace GetDiskFreeSpace.
But if you want to use GetDiskFreeSpace, why do you divide all numbers by 100?
-
oops, i copied some code from a previous project and forgot
to take out the dividing by 100. Still doesn't give me a correct
reading on the free space....
I'm not using GetDiskFreeSpaceEx because I need to know the
sectors and such.
Thanks again
-
Noble, I just said it was off - I'd written the core part of the reply before I got dragged off to do my presentation (on a course at the moment).
If you didn't notice the fact that I said you needed to follow the changes in the variables through to remove the dereferencing :p
Anyway, have you tried looking up GetDiskSpaceFree on MSDN?
-
thx parksie for your help, i realized what I did wrong before and
fixed it