Stuck w/ a simple ReadFile?!!!
-
I thought I would post this here because I can't spot the error. This is my first attempt to code for a Pocket PC. The following code works fine on the desktop:
TCHAR szFilePath[MAX_PATH]; wsprintf(szFilePath, TEXT("%sTest.txt"), this->szAppRootDirectory); HANDLE hFile = CreateFile(szFilePath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { MessageBox(hwnd, TEXT("Fatal error: Unable to open file."), NULL, MB_OK); return R_ERROR; } DWORD dwBytesRead; DWORD dwFileSize = SetFilePointer(hFile, 0, NULL, FILE_END); TCHAR *szBuffer = new TCHAR[dwFileSize + 1]; SetFilePointer(hFile, 0, NULL, FILE_BEGIN); ReadFile(hFile, szBuffer, dwFileSize, &dwBytesRead, NULL); CloseHandle(hFile); szBuffer[dwFileSize] = '\0';
Unfortunatelly, szBuffer fills w/ garbage (boxes) on the Pocket PC. Can anyone spot the error here? Thanks in advance. -
I thought I would post this here because I can't spot the error. This is my first attempt to code for a Pocket PC. The following code works fine on the desktop:
TCHAR szFilePath[MAX_PATH]; wsprintf(szFilePath, TEXT("%sTest.txt"), this->szAppRootDirectory); HANDLE hFile = CreateFile(szFilePath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { MessageBox(hwnd, TEXT("Fatal error: Unable to open file."), NULL, MB_OK); return R_ERROR; } DWORD dwBytesRead; DWORD dwFileSize = SetFilePointer(hFile, 0, NULL, FILE_END); TCHAR *szBuffer = new TCHAR[dwFileSize + 1]; SetFilePointer(hFile, 0, NULL, FILE_BEGIN); ReadFile(hFile, szBuffer, dwFileSize, &dwBytesRead, NULL); CloseHandle(hFile); szBuffer[dwFileSize] = '\0';
Unfortunatelly, szBuffer fills w/ garbage (boxes) on the Pocket PC. Can anyone spot the error here? Thanks in advance.Wouldn`t GetFileSize be an easier way to get the size of the file then moving the filepointer around? The fact that boxes are displayed could be that the characters in the file are ANSI characters(1byte) and you compiled your application for Unicode (TCHAR is then a wide char (2byte) ), or the other way around... Or the file contains unicode characters that are not supported by the font on your device... Hope this can help you further... Greetings, Davy
-
Wouldn`t GetFileSize be an easier way to get the size of the file then moving the filepointer around? The fact that boxes are displayed could be that the characters in the file are ANSI characters(1byte) and you compiled your application for Unicode (TCHAR is then a wide char (2byte) ), or the other way around... Or the file contains unicode characters that are not supported by the font on your device... Hope this can help you further... Greetings, Davy
That was the problem. Thanks.