Anyone have any examples of how to use this function? Thanks
Printable View
Anyone have any examples of how to use this function? Thanks
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; }
}}
Here is an example of how I use it...
With Visual Studio, cout has problems with __int64's, so you have to add something like this:PHP Code:__int64 userBytes;
__int64 totalBytes;
__int64 totalFreeBytes;
GetDiskFreeSpaceEx("C:",(PULARGE_INTEGER) &userBytes, (PULARGE_INTEGER) &totalBytes, (PULARGE_INTEGER) &totalFreeBytes);
Anyhow, the code above shows correct drive information for my drives under XP. Good luck.PHP Code:
ostream& operator<<(ostream& os, __int64 i )
{
char buf[20];
sprintf(buf,"%I64d", i );
os << buf;
return os;
};
great, thanks guys
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
no, it's too small
but I think sprintf supports 64-bit integers (look in the flags table)