简体   繁体   English

我的应用程序创建的Windows CE /嵌入式C ++非易失性文件在重新启动时被删除

[英]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++. 我正在使用C ++使用Windows Embedded Compact 7开发应用程序。 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. 我最近遇到的问题是,我在应用程序中创建并放置在\\ Mounted Volume(非易失性分区)上的.ini设置文件和.txt日志文件在重新启动时被删除。

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. 该应用程序正在打开.ini文件,编辑值,保存文件,并且下次启动时,它将具有我更新的设置。 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. 尽管它似乎与我的应用程序以及打开/编辑/保存/关闭文件的方式有关,因为如果我使用写字板打开.ini文件并手动编辑值然后保存,则设置将在重新启动后保存。 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. 我已经在MSDN上阅读过有关可能需要“刷新”打开的缓冲区的信息。 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. 我真的希望有人处理过Windows Embedded / CE,并且可能遇到过类似的非易失性文件分区问题,其作用类似于易失性内存。

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: 这是我用来写入日志文件的代码,该代码本质上与写入.ini文件的代码相同:

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. 如果您没有明确强制使用它,则文件系统可能会缓存写操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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