代码如下:
BOOL PopFileRead (HWND hwndEdit, LPTSTR pstrFileName)
{
//BYTE bySwap ;
int flag=0;
DWORD dwBytesRead ;
HANDLE hFile ;
int iFileLength ;
PBYTE pBuffer;
if (INVALID_HANDLE_VALUE ==
(hFile = CreateFile (pstrFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL)))
return FALSE ;
// Get file size in bytes and allocate memory for read.
// Add an extra two bytes for zero termination.
iFileLength =(int) GetFileSize (hFile, NULL) ;
pBuffer =(PBYTE) malloc (iFileLength+2) ;
ReadFile (hFile, pBuffer, iFileLength, &dwBytesRead, NULL) ;
CloseHandle (hFile) ;
pBuffer[iFileLength] = '\0 ' ;
pBuffer[iFileLength + 1] = '\0 ' ;
SetWindowText (hwndEdit, (PTSTR) pBuffer) ;
free (pBuffer) ;
return TRUE ;
}
用在PPC模拟器上时,读自己输入的可以,但读PPC WORD或电脑传过去的文本(unicode)时,却出现小方框和乱码.请各位指教。
------解决方案--------------------
unicode文本文件开始的两个字节是 FF FE 是标记文件是unicode编码, 这两个字节不是字符内码。