Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok I started this with a comment, but its getting out of control.</p> <p><strong>For Writing</strong></p> <p>This:</p> <pre><code>WCHAR *lpszText = new WCHAR[dwTextSize]; </code></pre> <p>should be:</p> <pre><code>WCHAR *lpszText = new WCHAR[dwTextSize+1]; </code></pre> <p>This:</p> <pre><code>DeleteObject(hTextFile); </code></pre> <p>should not be there <strong>at all.</strong>. Get rid of it.</p> <p>I'm assuming you <code>delete [] lpszText;</code> somewhere when you're done with it. if not, do so.</p> <hr> <p><strong>For Reading</strong></p> <p>The second parameter to <code>GetFileSize()</code> should not be the same variable as your return value. It is the HIGH 32bit of a 64-bit value for large file sizes. If you know you're file size is smaller than 4gB, you can leave it NULL, so change this:</p> <pre><code>DWORD dwFileSize = GetFileSize(hTextFile, &amp;dwFileSize); </code></pre> <p>to this:</p> <pre><code>DWORD dwFileSize = GetFileSize(hTextFile, NULL); </code></pre> <p>You must account for the null terminator of your file buffer, so this:</p> <pre><code>WCHAR *lpszText = new WCHAR[dwFileSize / 2]; </code></pre> <p>should be changed to this:</p> <pre><code>WCHAR *lpszText = new WCHAR[dwFileSize / 2 + 1]; lpszText[dwFileSize / 2] = 0; </code></pre> <p>and the rest should work as you're hoping it would. No error checking, which is not good, but I've seen worse. And as before, I'm assuming you <code>delete [] lpszText;</code> somewhere when you're done with it. if not, do so.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload