Determining the available free space in the Object Store or storage device is important before attempting to save large amounts of data, or for providing feedback to the user. Listing 3.1 shows how to obtain this information by calling GetDiskFreeSpaceEx. Listing 3.1 Displays free space in the object storevoid Listing3_1() { ULARGE_INTEGER ulFree, ulTotalBytes, ulTotalFree; // specify root directory in Object Store if(GetDiskFreeSpaceEx(_T("\\"), &ulFree, &ulTotalBytes, &ulTotalFree)) { cout _T("Bytes available to caller: ") tab ulFree.LowPart tab ulFree.HighPart endl; cout _T("Total number bytes: ") tab ulTotalBytes.LowPart tab ulTotalBytes.HighPart endl; cout _T("Total num. free bytes: ") tab ulTotalFree.LowPart tab ulTotalFree.HighPart endl; } else cout _T("Could not get free space: ") GetLastError(); }
The same function can be used to determine the free space in storage devices or network devices by passing the name of the directory entry representing the storage device (for example, "Storage Card") or network connection ("\Network\myresource"). Because of security restrictions the free bytes available to the caller may be less than the total free bytes. GetDiskFreeSpaceEx returns information in ULARGE structures. This structure contains a single member that is a ULONGLONG structure. You can get the low long and high long values using the LowPart and HighPart members. Windows CE also provides the GetStoreInformation for determining the size and free space in the Object Store. However, GetDiskFreeSpaceEx is more useful, as it can be used for any storage medium.
|