简体   繁体   中英

Windows CE/Embedded C++ non-volatile files created by my app being deleted on reboot

I am developing an application with Windows Embedded Compact 7 using C++. The problem I have just recently come across is that a .ini settings file and a .txt logfile that I create with the application and place on the \\Mounted Volume (which is a non-volatile partition) are being deleted on a reboot.

The application was working to open the .ini file, edit the values, save the file, and next time I booted up it would be there with the settings I updated. Only recently after a major software update did I start having problems. But the specific functions that deal with the opening and closing of the files were not touched during the update.

Although it seems like it is something related to my application and the way I open/edit/save/close the file because if I open the .ini file with Wordpad and edit values manually then save it, the settings are saved on a reboot. I also have appropriate error handling with all the functions and no errors are occurring.

I have read on MSDN about possibly needing to "Flush" open buffers. Possibly I need to do this? I was really hoping someone has dealt with Windows embedded / CE and has possibly ran across a similar issue of a non-volatile file partition acting more like volatile memory.

Thanks for any help! Here is the code that I am using to write to a logfile which is essentially the same code as writing to the .ini file:

int writeLogFile(const char* szString)

{

FILE* pFile;

  if((pFile = fopen("\\Mounted Volume\\logFile.txt", "a+")) == NULL )

    debugMessage("Function: writeLogFile - Error! Could not open logFile.txt\n\r");

  else

    debugMessage("Function: writeLogFile - Notice. Opened logFile.txt\n\r");

  if(fprintf(pFile, "%s\r",szString) < 0)

    debugMessage("Function: writeLogFile - Error! There was a problem writing the alarm string to logFile.txt.\n\r");

  if(fclose(pFile))

    debugMessage("Function: writeLogFile - Error! Could not close logFile.txt\n\r");

  else

    debugMessage("Function: writeLogFile - Notice. Closed logFile.txt\n\r");

  return 1;

}

Could you try to ad a fflush call before you close the file. That should force an actual write. If you don't force it explicitely the file system may cache the writes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM