Accessing Data on Other Storage Media

A Windows CE–based device has other areas to store applications besides the object store. You can access a file stored in ROM just like any other file: by calling the file application programming interface (API). However, you cannot alter a file that is stored in ROM. Instead, ROM-based files are marked with the FILE_ATTRIBUTE_INROM value, indicating that they are read-only. Windows CE also uses the FILE_ATTRIBUTE_ROMMODULE value to indicate that a file is designated to be executed in ROM, rather than copied to RAM. You cannot use CreateFile to open files that are designated with FILE_ATTRIBUTE_ROMMODULE. Instead, use the LoadLibrary and CreateProcess functions to gain access to the module.

Also, Windows CE supports PC Cards, such as Advanced Technology Attachment (ATA) flash cards, and linear flash cards. These cards can have an installed file system that can utilize the storage space for files and databases. However, a mounted file system must be used in conjunction with an installed file system driver, such as FAT. Once you install a PC Card, you can copy database objects between the object store and the mounted volume.

Windows CE does not assign a letter label to a storage card in the same manner that a desktop computer assigns a drive letter to a hard disk. Instead, the file driver creates directories in the root directory representing each partition on each storage card. In Windows CE 2.0 and earlier, these directories were given default names, such as Storage Card or PC Card. In Windows CE 2.10, the FAT file system driver queries the PC Card driver for a default name. If the PC Card driver does not supply a default name, Windows CE uses Storage Card. You can also tell the difference between a object store directory and a mounted volume directory by the file attributes. All directories on a mounted file system have the FILE_ATTRIBUTE_TEMPORARY file attribute flag set.

The following code example tries to open any Storage Card directories that exist and tests them to see if they are located on a storage card.

void FindingStorageCards (void)
{
  TCHAR szMsg[100];       // String to store the error message
  HANDLE hSearch;         // Search handle returned by FindFirstFile
  WIN32_FIND_DATA  fd;    // Data structure describes the file found
  BOOL bFinished = FALSE; // Flag to indicate whether the loop is done
  TCHAR *szFname = TEXT("\\Storage Card*");
                          // Name that matches all storage cards

  // Be sure Storage Card exists.
  hSearch = FindFirstFile(szFname, &fd);

  if (hSearch == INVALID_HANDLE_VALUE)
  {
    wsprintf(szMsg, TEXT("No storage card found."));
    return;
  }

  do {
    // Test whether the file is really on a storage card, and
    // not just a directory in the root directory.
    // It must have both the directory attribute and
    // the temporary attribute.

    if (  (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)
       && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
    {
      wsprintf (szMsg,
                TEXT("%s is a storage card."), fd.cFileName);
    }
    else
    {
      wsprintf (szMsg,
                TEXT("%s is not a storage card."), fd.cFileName);
    }

    if (!FindNextFile (hSearch, &fd))
    {
      bFinished = TRUE;
      if (GetLastError () != ERROR_NO_MORE_FILES)
      {
        wsprintf (szMsg,
                  TEXT("Error trying to find files matching \"%s\"."),
                  szFname);
      }
    }
  }
  while (!bFinished);

  FindClose (hSearch);  // Close the search handle.

} // End of FindingStorageCards example code