11.txt编码为Unicode
---------------------------------------------------------------------------
HANDLE hFile = CreateFile(_T("F:\\11.txt"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(INVALID_HANDLE_VALUE != hFile)
{
DWORD dwSize = GetFileSize(hFile, NULL);
wchar_t* szText = new wchar_t[dwSize+1];
memset(szText, 0, sizeof(wchar_t) * (dwSize+1));
DWORD dwRead = 0;
if(INVALID_SET_FILE_POINTER != SetFilePointer(hFile, 2, NULL, FILE_BEGIN))
{
if(ReadFile(hFile, szText, dwSize, &dwRead, NULL))
{
char* buf = NULL;
int len = WideCharToMultiByte(CP_ACP, 0, szText, -1, buf, 0, NULL, NULL);
buf = new char[len];
memset(buf, 0, len);
WideCharToMultiByte(CP_ACP, 0, szText, -1, buf, len, NULL, NULL);
printf("%s\r\n", buf);
delete[] buf;
buf = NULL;
}
}
delete[] szText;
szText = NULL;
CloseHandle(hFile);
}
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.