Sign in to follow this  

Windows Service - file writing.

This topic is 3856 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
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

This topic is 3856 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this