C++, function that loads text ignores last few lines with only some of the .txt files <p>I'm following theForger's Win API tutorial to load text files into an edit control. Sometimes the entire file is loaded correctly and sometimes the last part of it is left out, where 'part' is in one case 2 and a half lines and in another 10 lines o_O Here's how the files look:</p> <p>(I'm a new user so it's not letting me post more than one hyperlink, so here's the gallery where the screenshots are: <a href="http://nancy.imgur.com/all/" rel="nofollow">http://nancy.imgur.com/all/</a> and I'm referring to the order in which they appear in the gallery)</p> <p>2.5 lines left out: second (reading stops at the cursor after the 'F')</p> <p>10 lines left out: fourth (also stops at the cursor after the f)</p> <p>Read completely: first and third</p> <p>I tried using fstreams instead, and the same stuff was left out (I also couldn't get the new line characters to show in the edit control =( ). Any idea what could be wrong?</p> <p>I couldn't link to theForger's tutorial so here's the function:</p> <pre><code>BOOL LoadTextFileToEdit(HWND hEdit, LPCTSTR pszFileName) { HANDLE hFile; BOOL bSuccess = FALSE; hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(hFile != INVALID_HANDLE_VALUE) { DWORD dwFileSize; dwFileSize = GetFileSize(hFile, NULL); if(dwFileSize != 0xFFFFFFFF) { LPSTR pszFileText; pszFileText = GlobalAlloc(GPTR, dwFileSize + 1); if(pszFileText != NULL) { DWORD dwRead; if(ReadFile(hFile, pszFileText, dwFileSize, &amp;dwRead, NULL)) { pszFileText[dwFileSize] = 0; // Add null terminator if(SetWindowText(hEdit, pszFileText)) bSuccess = TRUE; // It worked! } GlobalFree(pszFileText); } } CloseHandle(hFile); } return bSuccess; } </code></pre>