|
-
Apr 5th, 2002, 09:07 PM
#1
Thread Starter
Hyperactive Member
using GetDiskFreeSpaceEx
Anyone have any examples of how to use this function? Thanks
Matt 
-
Apr 6th, 2002, 03:53 AM
#2
Code:
typedef BOOL (WINAPI* PFNGETDISKFREESPACEEX)(LPCTSTR,
PULARGE_INTEGER,
PULARGE_INTEGER,
PULARGE_INTEGER);
if((hModule = ::LoadLibrary("KERNEL32.DLL"))){
PFNGETDISKFREESPACEEX pDiskFreeSpaceEx = NULL; // Get free space on partition
if(!(pDiskFreeSpaceEx = (PFNGETDISKFREESPACEEX) ::GetProcAddress(hModule, "GetDiskFreeSpaceExA")))
{DWORD dwSectorsPerCluster = 0;
DWORD dwBytesPerSector = 0;
DWORD dwFreeClusters = 0;
DWORD dwClusters = 0;
if(::GetDiskFreeSpace(m_DriveInfo.m_aPartitions[iIndex].m_szRoot,
&dwSectorsPerCluster,
&dwBytesPerSector,
&dwFreeClusters,
&dwClusters) == FALSE) {
// Error // Release library ::FreeLibrary(hModule);
return; }
ULARGE_INTEGER uliTotalNumberOfBytes;
ULARGE_INTEGER uliTotalNumberOfFreeBytes;
uliTotalNumberOfBytes.QuadPart = dwClusters * dwBytesPerSector * dwSectorsPerCluster;
uliTotalNumberOfFreeBytes.QuadPart = dwFreeClusters * dwBytesPerSector * dwSectorsPerCluster; }
else {
ULARGE_INTEGER uliFreeBytesAvailableToCaller;
ULARGE_INTEGER uliTotalNumberOfBytes;
ULARGE_INTEGER uliTotalNumberOfFreeBytes;
if(::GetDiskFreeSpaceEx(m_DriveInfo.m_aPartitions[iIndex].m_szRoot,
&uliFreeBytesAvailableToCaller,
&uliTotalNumberOfBytes,
&uliTotalNumberOfFreeBytes) == FALSE) {
// Error // Release library ::FreeLibrary(hModule);
return; }
}}
-
Apr 6th, 2002, 01:52 PM
#3
New Member
Hi
Here is an example of how I use it...
PHP Code:
__int64 userBytes;
__int64 totalBytes;
__int64 totalFreeBytes;
GetDiskFreeSpaceEx("C:",(PULARGE_INTEGER) &userBytes, (PULARGE_INTEGER) &totalBytes, (PULARGE_INTEGER) &totalFreeBytes);
With Visual Studio, cout has problems with __int64's, so you have to add something like this:
PHP Code:
ostream& operator<<(ostream& os, __int64 i )
{
char buf[20];
sprintf(buf,"%I64d", i );
os << buf;
return os;
};
Anyhow, the code above shows correct drive information for my drives under XP. Good luck.
Last edited by chachi; Apr 6th, 2002 at 04:18 PM.
-
Apr 7th, 2002, 04:46 PM
#4
Thread Starter
Hyperactive Member
Matt 
-
Apr 9th, 2002, 06:47 PM
#5
Thread Starter
Hyperactive Member
I was wondering could I use just plain 'int' as the data type becasue I have to display it in a message box which needs to convert it from a integer to string format. Thanks
Matt 
-
Apr 10th, 2002, 07:51 AM
#6
no, it's too small
but I think sprintf supports 64-bit integers (look in the flags table)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|