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);// 读出来的内容显示为乱码
改成CString fn="c:\\a.txt"
改成CString fn="c:\\a.txt"
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.