PDA

Click to See Complete Forum and Search --> : GetDiskFreeSpace


noble
Jan 17th, 2002, 09:01 AM
Can someone help me out with the GetDiskFreeSpace API?

Here is what i have and i'm getting values that don't seem correct.


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

parksie
Jan 17th, 2002, 09:17 AM
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.


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...

noble
Jan 17th, 2002, 09:28 AM
still seem off by a little.....


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;

CornedBee
Jan 17th, 2002, 09:50 AM
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?

noble
Jan 17th, 2002, 09:58 AM
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

parksie
Jan 17th, 2002, 10:51 AM
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?

noble
Jan 17th, 2002, 12:11 PM
thx parksie for your help, i realized what I did wrong before and
fixed it