Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Stuck w/ a simple ReadFile?!!!

Stuck w/ a simple ReadFile?!!!

Scheduled Pinned Locked Moved Mobile
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    georgiek50
    wrote on last edited by
    #1

    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.

    G 1 Reply Last reply
    0
    • G georgiek50

      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.

      G Offline
      G Offline
      GDavy
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • G GDavy

        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

        G Offline
        G Offline
        georgiek50
        wrote on last edited by
        #3

        That was the problem. Thanks.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups