HANDLE file;
  char W_c[20];
  DWORD dwBytesRead;
  CString fn="c:\a.txt";

  file=CreateFile(fn,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);
  if(file==INVALID_HANDLE_VALUE)
        MessageBox("打开错误");//这步测试正确
  BOOL tf= ReadFile(file,W_c,20,&dwBytesRead,0);//为什么读不出来内容
  if(tf==0)
     MessageBox("读错误");  //显示
  
  W_c[5]='\0';
  MessageBox(W_c);//  读出来的内容显示为乱码

解决方案 »

  1.   

    先 memset(W_c,0,20);BOOL tf= ReadFile(file,W_c,19,&dwBytesRead,NULL);去掉W_c[5] = '\0'试试
      

  2.   

    CString fn="c:\a.txt";写错
    改成CString fn="c:\\a.txt"
      

  3.   

    CString fn="c:\a.txt"; ====>>CString fn="c:\\a.txt";
      

  4.   

    你的a.txt里面的内容有多于20个吗?
      

  5.   

    文本路径不对
    改成CString fn="c:\\a.txt"
      

  6.   

    多于.都200多K了.路径我写的就是"c:\\a.txt".我上面写错了
      

  7.   

    BOOL ReadFile(     HANDLE hFile, // handle of file to read 
        LPVOID lpBuffer,  // address of buffer that receives data 
         DWORD nNumberOfBytesToRead,  // number of bytes to read 
        LPDWORD lpNumberOfBytesRead,  // address of number of bytes read 
        LPOVERLAPPED lpOverlapped   // address of structure for data 
        ); 
     If hFile was opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must not be NULL. It must point to a valid OVERLAPPED structure. If hFile was created with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function can incorrectly report that the read operation is complete.