Mounting and Unmounting a Database Volume

In order to create and use a database volume with Windows CE 2.10 and later, you must first mount, or open, the volume. This does not include the object store, which is always mounted and identified by a system globally unique identifier (GUID). Once all operations are complete, you must unmount, or close, the volume. Mounting and unmounting adds a level of complexity to your database programming but allows you to store a database elsewhere on a device besides the object store. Note that you can still use the original database API in Windows CE 2.10 and later to gain access to a database in the object store. However, the earlier API exists for backward compatibility only; all new applications should use the new API.

Call the CeMountDBVol function to mount a volume that can store Windows CE databases on any file system. This file system can include the object store or an installed file system, such as the FAT file system on a PC Card. CEMountDBVol acts as a specialized version of CreateFile; instead of opening or creating a generic file, CEMountDBVol opens or creates a database volume. CEMountDBVol accepts the location of the file that is the database volume and returns a PCEGUID. Functions designed to manipulate mounted database volumes use the PCEDUID as a handle to identify a given volume.

Call the CEUnmountDBVol function to unmount a database volume. Like CloseHandle, CeUnmountDBVol returns resources that the database volume was using back to the system. To be sure that Windows CE writes any cached data to permanent storage, call the CeFlushDBVol function prior to unmounting the volume. The database can also be closed by user reset or a power failure. Because Windows CE automatically flushes the cache on a periodic basis, you will lose only data altered since the last cache flush. Also, the volume itself is not altered by a power failure or reset.

Note that more than one process can mount the same database volume. Windows CE keeps track of how many processes have access to a given database volume. When the last process unmounts the database, Windows CE closes the file.

The following code example shows how to unmount a database volume. For an example showing how to mount a database volume, see "Mounted Database Example."

void UnmountingDBs (PCEGUID pceguid)
{
  TCHAR szMsg[100];

  if (!CeUnmountDBVol (pceguid))
  {
    wsprintf (szMsg, TEXT("Failed unmounting the database."));

    // Your error-handling code goes here.
  }
} // End of UnmountingDBs example code