title: CFile read data to buffer
body: <p>I'm trying to get all the bytes from a file to read on a BYTE* variable. I'm trying to read a whole xml file data into memory which looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;DataBlock xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;Device&gt;3867242&lt;/Device&gt;
      &lt;Manufacturer&gt;COMPANY LTD&lt;/Manufacturer&gt;
      &lt;Data&gt;15&lt;/Data&gt;
      &lt;VendorID&gt;00-291-647&lt;/VendorID&gt;
      &lt;TimeStamp&gt;2014-08-13 12:40:11&lt;/TimeStamp&gt;
  &lt;/DataBlock&gt;
  </code></pre>
  
  <p>But ending up with reading something like:</p>
  
  <pre><code>"&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;DataBlock xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;Device&gt;3867242&lt;/Device&gt;
      &lt;Manufacturer&gt;COMPANY LTD&lt;/Manufacturer&gt;
      &lt;Data&gt;15&lt;/Data&gt;
      &lt;VendorID&gt;00-291-647&lt;/VendorID&gt;
      &lt;TimeStamp&gt;2014-08-13 12:40:11&lt;/TimeStamp&gt;
  &lt;/DataBlock&gt;ýýýý««««««««þ"
  </code></pre>
  
  <p>Below is the code to read it..</p>
  
  <pre><code>CFile oFile;
  if(oFile.Open(filePath, CFile::modeRead) == FALSE)
    return NULL;
  
  long iFileSiz = oFile.GetLength();
  BYTE* pData = new BYTE[iFileSiz];
  
  oFile.Read(pData, iFileSiz);
  oFile.Close();
  </code></pre>
  
  <p>I'm getting some garbage character at the end of buffer or some files couldn't be read completely. </p>
  
  <p>Output is captured from Visual studio debugger. </p>