Is there a file path string to use with fopen() that will create a file in a user's Desktop folder no matter which user logs in and runs the program?
For example something like:
fopen("C:\home...\folder...\Desktop\file.txt","w")
Is there a file path string to use with fopen() that will create a file in a user's Desktop folder no matter which user logs in and runs the program?
For example something like:
fopen("C:\home...\folder...\Desktop\file.txt","w")
This should get you started:
SHGetSpecialFolderPath function (Windows)
CSIDL (Windows) (CSIDL_DESKTOPDIRECTORY)
gg
Thanks for the response.
Coming from a UNIX programming environment the only thing I'm able to get from these references is that it is (may be?) possible to determine the Desktop folder path somehow. But it looks like implementing the information assumes additional background knowledge of Windows programming. So I'm still searching for the answer. A code example would be most helpful.
Can you use an environment variable such as %HOMEPATH% in a file name? If not, you will have to use something like environ() to get the partial file name path.
Reading Windows man-pages (MSDN) takes some getting used to. If you don't know a typedef that's being used: Windows Data Types (Windows)Code:#include<stdio.h> #include<windows.h> #include<ShlObj.h> int main() { char desktop[MAX_PATH] = {0}; if (!SHGetSpecialFolderPathA(0, desktop, CSIDL_DESKTOPDIRECTORY, FALSE)) { printf("SHGetSpecialFolderPath() failed, le=%u\n", GetLastError()); return 1; } printf("Desktop Path = %s\n", desktop); return 0; }
gg