Jump to content
  • Advertisement
Sign in to follow this  
TelevirtualSoftDev

Windows Service - file writing.

This topic is 4067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently putting an application I have created into a windows service. I have a problem where ofstream does not appear to be working in my test service application. In this code example below, when I run from the services window, the FILE method writes to file but the ofstream does not although both work when run from VC++. Any help with this issue would be much apprecated. if(logging){ char* logNote = new char[1000]; TimeAndDate sysTime; sysTime.GetScreenTimeWithSeconds(logNote); strcat(logNote," - "); strcat(logNote,logInfo); strcat(logNote,"\n"); //findlogfilename char* logFileName = new char[500]; char* logDate = new char[500]; sysTime.GetDate(logDate); strcpy(logFileName,"RssServerLog"); strcat(logFileName,logDate); strcat(logFileName,".dat"); //open file where seek set at end,app - ignores any further seek command fstream logFile; logFile.open(logFileName, ios::app); logFile << logNote; logFile.close(); logFile.clear(); FILE* log; log = fopen("C:\\memstatus2.txt", "a+"); //if (log == NULL) //return -1; fprintf(log, "%s\n", logNote); fclose(log); }

Share this post


Link to post
Share on other sites
Advertisement
Who is the service run as and can it interact with desktop? The stream may require a desktop environment though I do not know for certain.

Share this post


Link to post
Share on other sites
Hi.
I've solved this error.

I declared the variable as fstream - this works when opening the program normally but not when as a service. Need to use ofstream/ifstream.

Now it writes the file

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!