Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

in my MFC application, I set a timer and do something at timer, writting something realtime data; the code is:  

//MyApplication.cpp  
OnTimer() FILE* pfile = NULL; 
errno_t errRet = _tfopen_s( &pfile, _T("process.txt"), _T("a") ); 
if ( 0!=errRet && NULL == pfile ) 
{ 
TRACE(_T("errRet=%d, pfile=%p, LastErr=%d\n"), errRet, pfile, GetLastError() );
 } 
//end 

sometimes(just very low chance to see it), the if condition is FALSE, and trace is :"errRet=13,pfile=0x00000000, LastErr=183" in my application, there is just one thread(UI main thread) operating this file, so no synchronization. please somebody give me some explain about this BUG!!! thanks!

Posted
Updated 26-Nov-09 16:59pm
v3

It doesn't matter if nothing else in your app is accessing the file. If anything holds an open handle on the file then your app will fail to open it. A text editor, log viewer, indexing service maybe... It's outside of your control.

There are other reasons why this might be failing as well. For starters, you aren't specifying a location for the file. Either you're setting the CWD explicitly elsewhere, or you're relying on it being a location you can actually write to... Check both of these assumptions.

 
Share this answer
 

Why did you post this three times ? Is this C, or C++ ? If it's C++, why on earth are you using a FILE* and not iostreams ? If it''s C, why is your code file .cpp ? Whatever the underlying issue, there is no reason I can see to use C file handling in C++, except ignorance.

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900