本文介绍了为什么_tfopen_s()返回错误值13或2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MFC应用程序中,我设置了一个计时器并在该计时器上进行了一些操作,编写了一些实时数据;代码是: 

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 

有时(看到它的机会很小),如果条件为FALSE,并且跟踪为:"errRet = 13,pfile = 0x00000000,LastErr = 183"在我的应用程序中,只有一个线程(UI主线程) )操作此文件,因此无法同步.请有人给我一些关于这个错误的解释!!!谢谢!

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!

推荐答案

还有其他可能导致此失败的原因.对于初学者,您无需指定文件的位置.要么在其他地方显式设置CWD,要么依赖于它实际上是您可以写入的位置...检查这两个假设.

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.



这篇关于为什么_tfopen_s()返回错误值13或2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 07:40