m_Filename是文件名字所在的编辑框变量名
m_readandwrite是用来放读到的内容的编辑框变量名
因为我写入文件的编码形式是UNICODE,但是用读出文件的代码去读会乱码
读出文件的代码读ANSI不会出问题
所以想问怎么读UNICODE的TXT怎么读。。。。
下面是读ANSI的代码。。。
HANDLE handle = CreateFile(m_Filename, GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (handle != INVALID_HANDLE_VALUE) {
char read[1024];
DWORD nBytesRead = 0xFEFF;
while (true) {
UpdateData(true);
ZeroMemory(read, 1024);
BOOL bResult = ReadFile(handle, read, 1024, &nBytesRead, NULL);
if (bResult && (nBytesRead == 0)) {
break;
}
CString readstr(read);
m_readandwrite.Format(readstr);
UpdateData(false);
}
CloseHandle(handle);