Chapter 8, the Smartphone extends a standard shell call that will return the proper subdirectory in which an application can store its data.
The function SHGetSpecialFolderPath was Chapter 16. The Smartphone adds an additional constant, CSIDL_APPDATA. Using this CSIDL value will return the name of the application data folder that is persistent. An application can then create a subdirectory under the persistent folder where it can store its data. Because the persistent folder is used by all applications, you should be careful to uniquely name your application's directory. The following code demonstrates finding the application data folder and creating a directory.
int CreateAppFolder (HWND hWnd, TCHAR *pszAppFolder, int nMax) { const TCHAR szMyAppFolderName[] = TEXT ("ProgWinCESpSample"); TCHAR szPath[MAX_PATH]; // It doesn't help to have a path longer than MAX_PATH if (nMax > MAX_PATH) nMax = MAX_PATH; BOOL f = SHGetSpecialFolderPath (hWnd, szPath, CSIDL_APPDATA, FALSE); // See if everything will fit in output string int nLen = lstrlen (szPath); if (nLen + 2 + (int)lstrlen (szMyAppFolderName) > nMax) return -2; // Copy app folder name to parameter lstrcpy (pszAppFolder, szPath); // Append directory separator character as needed if (szPath[nLen] != TEXT ('\\')) lstrcat (pszAppFolder, TEXT("\\")); // Append my folder name lstrcat (pszAppFolder, szMyAppFolderName); // See if directory exists. if (GetFileAttributes (pszAppFolder) == 0xffffffff) { // See why call failed if (GetLastError () == ERROR_PATH_NOT_FOUND) { // Wasn't there, create the directory if (!CreateDirectory (pszAppFolder, NULL)) return -3; } else return -4; // Dir created but inaccessible } else return 1; // Indicate directory already exists return 0; // Indicate directory created }
Data stored in the registry is persistent. The Smartphone takes steps to save and restore the registry when the system shuts down and starts back up.