Ah, solo un altro appunto: un intero a 32 bit, come ben saprai, tiene valori fino a circa 4 miliardi, che sono circa 4 Gb.
Il che significa che la funzione, così come tu la usi, non potrà mai restituirti il valore dello spazio libero quando questo è superiore a 4 Gb!
Qui sotto uno spezzone dal sito MS che ti mostra che tipi di variabili usare!
codice:
#include <windows.h>
#include <stdio.h>
typedef BOOL (WINAPI *PGETDISKFREESPACEEX(LPCSTR,
PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
BOOL MyGetDiskFreeSpaceEx(LPCSTR pszDrive)
{
PGETDISKFREESPACEEX pGetDiskFreeSpaceEx;
__int64 i64FreeBytesToCaller, i64TotalTypes, i64FreeBytes;
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;
BOOL fResult;
pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32.dll"),
"GetDiskFreeSpaceExA");
if (pGetDiskFreeSpaceEx)
{
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
// Process GetDiskFreeSpaceEx results.
printf("Total free bytes = %I64d\n", i64FreeBytes);
}
else
{
fResult = GetDiskFreeSpace (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters);
// Process GetDiskFreeSpace results.
printf("Total free bytes = I64d\n",
dwFreeClusters*dwSectPerClust*dwBytesPerSect);
}
}
RiCiao!