Getting Object Store Free Space

< BACK  NEXT >
[oR]

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 lpDirectoryName Storage device for which to obtain information
PULARGE_INTEGER lpFreeBytesAvailableToCaller Number of bytes of storage available to this user
PULARGE_INTEGER lpTotalNumberOfBytes Total number of bytes of storage
PULARGE_INTEGER lpTotalNumberOfFreeBytes Total number of free bytes of storage
BOOL Return Value Nonzero 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 ("\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.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net