CFile hfil;          
WIN32_FIND_DATA fd;
 HANDLE hd=::FindFirstFile("usrinfo\\*.*",&fd);
 if (hd==INVALID_HANDLE_VALUE)
 GetLastError();
if(hfile.Open((const char*)fd.cFileName,CFile::modeRead==HFILE_ERROR)
 GetLastError();
 CString hostname,macaddr,date;
 char buffer[100]
 hfile.Read(buffer,6);
这一段去掉hfile.Read程序可以正常运行,但是加上后就出错,我用GetLastError()
发现前面的函数调用都是成功的但是为什么Read出错呢??????
请大家帮忙啊!!!
谢谢!!!

解决方案 »

  1.   

    CFile::modeRead==HFILE_ERROR这里有问题
    HFILE_ERROR是-1
    CFile::modeRead是0,2者不相等
    直接用
    if(hfile.Open((const char*)fd.cFileName,CFile::modeRead)
    试试看吧
      

  2.   

    对不起,刚才是我打错了,应该是这样写的:
    if(hfile.Open((const char*)fd.cFileName,CFile::modeRead)==HFILE_ERROR)
      

  3.   

    hfile.Open((const char*)fd.cFileName,CFile::modeRead|CFile::typeBinary)  
    是不是应该这样?
      

  4.   

    什么错误?GetLastError返回什么?
      

  5.   

    就是GetLastError()没有返回错误信息啊,应该说明findfirstfile和open函数调用都是成功的,那就是说read这句有错啊。
      

  6.   

    GetLastError();放到read之后,看看什么错误