Getting Object Store Free Space

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 store
void 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();
}

Table 3.1. GetDiskFreeSpaceEx—Gets information on available storage space
GetDiskFreeSpaceEx 
LPCWSTR lpDirectoryNameStorage device for which to obtain information
PULARGE_INTEGER lpFreeBytesAvailableToCallerNumber of bytes of storage available to this user
PULARGE_INTEGER lpTotalNumberOfBytesTotal number of bytes of storage
PULARGE_INTEGER lpTotalNumberOfFreeBytesTotal number of free bytes of storage
BOOL Return ValueNonzero indicates success. Zero indicates failure

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 ("Networkmyresource"). 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.33.41