Have any of you found a better way to write to files in the application directory other than this:
I didn't want my files to be written to the "My Device" directory, and this is the best way I could come up with for keeping them in the application directory. The standard fopen command doesn't like TCHAR (unsigned short) types for the filename, so I just loop through to put them into a char array.
If this was stumping you too, feel free to use the code. If you see a potential failure in the code, please let me know.
- Code:
FILE *fp;
#if defined(_WIN32_WCE)
TCHAR pathname[MAX_PATH];
char filename[MAX_PATH];
// get the path and copy it into a char array
PocketPC::GetFullPathName( _T("filename.txt"), pathname );
for(int i=0; i<MAX_PATH; i++)
filename[i] = (char) pathname[i];
if(!(fp = fopen(filename, "w")))
#else
if(!(fp = fopen("filename.txt", "w")))
#endif
// couldn't open file...
return;
// file opened successfully
fprintf(fp, "blah blah blah");
fclose(fp);
I didn't want my files to be written to the "My Device" directory, and this is the best way I could come up with for keeping them in the application directory. The standard fopen command doesn't like TCHAR (unsigned short) types for the filename, so I just loop through to put them into a char array.
If this was stumping you too, feel free to use the code. If you see a potential failure in the code, please let me know.