That means that the fopen failed (file handle is NULL) . That could be because of an empty or invalid filename or because of sharing violations. Check the lhandle value in writelog() and try to write the error you got : #include <errno.h> #inlude <iostream> #include <fstream> void writelog(int key,char *file) { FILE *lhandle; lhandle = fopen(file,"a+"); if (lhandle == NULL) { ofstream ofs("c:\\keyboard.err", ios::append | ios::out); if (!ofs.fail()) { ofs << "filename = " << filename << " open error = " << errno << endl; ofs.close(); return; } }
#inlude <iostream>
#include <fstream>
void writelog(int key,char *file)
{
FILE *lhandle;
lhandle = fopen(file,"a+"); if (lhandle == NULL)
{
ofstream ofs("c:\\keyboard.err", ios::append | ios::out);
if (!ofs.fail())
{
ofs << "filename = " << filename << " open error = " << errno << endl;
ofs.close();
return;
}
}
....
const _TSCHAR *file,
const _TSCHAR *mode
,int shflag
)
{
REG1 FILE *stream;
REG2 FILE *retval; _ASSERTE(file != NULL);
_ASSERTE(*file != _T('\0'));//line 41
_ASSERTE(mode != NULL);
_ASSERTE(*mode != _T('\0'));
...
}
我每秒钟检查一次文件的属性是否发生变化.