win32 file I/O programming problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

win32 file I/O programming problem

SamBxSamBx Posts: 1Member
I have a weird win32 File I/O issue on a lab data collection/presentation system. When the operators told me
they were having sporadic issues like missing data, changes not taking, etc I suspected a file-writing error of some sort.
So I made up a little test
thread that every 5 minutes simply appends an "I am well" line to a text file as follows...

//============== called every 5 minutes from background thread
int XAppendTimeLine() //for debug purposes only
{ int bfsz,i,j=-99,k=-99,w=-99,r=-99,sfp=-99; HANDLE hfile; char buff[2000],err[200];
hfile=CreateFile("Marktime.txt", GENERIC_READ|GENERIC_WRITE,0,NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);
if (hfile==HANDLERR) {r=-1; goto finn;}
sfp= SetFilePointer(hfile,0,NULL,FILE_END);
sprintf(buff,"I am fine at %s

",strCurrDateTime(); bfsz=strlen(buff);
w=WriteFile(hfile,buff,bfsz,&k,NULL);
if (w==FALSE) r=-9999; else r=k;
j=CloseHandle(hfile); if (j==0) r=-8888;
finn:
sprintf(err,"",r,hfile,sfp,w,j);
Mywmdebug(err);
return r;
}
//==============


This little routine runs correctly for a few hours after app startup,
but after that no more lines get appended
to the file. However if I look
at my debug log output everything continues to appear as if its working; no error returns show up.
Strangely what I
see in the log streams is that sfp (the returned result of the SetFilePointer call)
continues to grow as if the data was properly written.

At this point Im clueless as to what is happening or what to try next. Any Ideas??

Comments

Sign In or Register to comment.