My app needs to create a directory to store some files it uses. Is there a standard place to do this under Win32? (I mostly program Mac OS X where the answer to this question is ~/Library/Application Support/)
My app needs to create a directory to store some files it uses. Is there a standard place to do this under Win32? (I mostly program Mac OS X where the answer to this question is ~/Library/Application Support/)
Windows uses \Temp directory to store temporary files.
You can also store some application related information to registry in windows but it is not a proper place to store files.
Otherwise select directory your self and store your files within that directory.
Chintan R Naik
Thanks. I use the registry to store preferences data, but these files are several 100k. I'm currently creating a directory in the user's home directory and putting them in it. I guess that's OK for Windows.
Windows defines a directory for user application data, whose path you can look for in the registry. The Temp folder is intended for files that will be created, used, and then deleted afterwards.
Peter O. Programming tips
What registry entry should be used? HKEY_CURRENT_USER\Volatile Environment\APPDATA? Is it consistent over all Win32 platforms?
Thanks, Nick
How about this:
http://msdn.microsoft.com/library/de...ettemppath.asp
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Thanks Hammer, but isn't that only for temporary files? I'm looking for a place to store application data (some of which are largish files that persist between launches).
Yeah, sorry, I kinda missed your point there
How about this one instead:
http://msdn.microsoft.com/library/de...tallations.asp
Any good?
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Here's code that may be relevant:
Code:} BOOL GetShellFolderPath(char * pShellFolder, char * pShellPath) { // pShellFolder can be one of the following // AppData, Cache, Cookies, Desktop, Favorites, // Fonts, History, NetHood, // Personal, Printhood, Programs, Recent, // SendTo, Start Menu, Startup, // Templates, ShellNew DWORD rc; DWORD length = MAX_PATH; DWORD type = REG_SZ; HKEY hkey; rc = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\" "Explorer\\Shell Folders", 0, KEY_READ, &hkey); if (rc == ERROR_SUCCESS) { rc = RegQueryValueEx(hkey, pShellFolder, NULL, &type, (BYTE *) pShellPath, &length); RegCloseKey(hkey); } if (rc == ERROR_SUCCESS) return TRUE; else return FALSE; }
Peter O. Programming tips
Thank you Poccil and Hammer! Based on the MSDN article and the sample code, I was able to get this to work. The path is HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\Shell Folders and the key is AppData.
For reference SHGetFolderPath is the recommended function to get folder locations. However for backwards compatibility one must include the 22KB redistributable Shfolder.dll with an application.
This should be more reliable than reading the registry directly.
See:
http://msdn.microsoft.com/library/en...folderpath.asp
http://www.mvps.org/vbnet/index.html...owse/csidl.htm
That's true. Perhaps the best solution is to dynamically link to shfolder.dll, or check the registry if the file doesn't exist.
Peter O. Programming tips
Sounds like it might be better for native apps.
My app is actually Java with a little platform-specific code to handle these sort of issues. It turns out that I can use existing code to get access to the registry, which avoids the problems of DLL's, native methods, etc. So I'm sticking with what I've got - so far it tests out fine.
Thanks everyone.