Looking at the documentation for CFile::Read
, we see that it takes two parameters:
virtual UINT CFile::Read(void* lpBuf, UINT nCount);
lpBuf
Pointer to the user-supplied buffer that is to receive the data read from the file.
nCount
The maximum number of bytes to be read from the file. For text-mode files, carriage return–linefeed pairs are counted as single characters.
lpBuf is not of type CByteArray
. It is void*
. Thus the compiler error.
To read into a CByteArray
, we need to allocate a buffer via CByteArray
and get a pointer to said buffer that we can use for lpBuf:
CByteArray buffer;
buffer.SetSize(1024); // ensure that buffer is allocated and the size we want it
UINT bytesRead = myFile.Read(buffer.GetData(), buffer.GetSize());
// use bytesRead value and data now in buffer as needed
Note, that in your question, you have the following line on the read path:
if(myFile.Open(_T(file), CFile::modeReadWrite | CFile::modeCreate))
The CFile::modeCreate
will cause the file to be truncated to 0 bytes. There won't be anything to read.
Did you mean to write something more like this?
if(myFile.Open(_T(file), CFile::modeRead | CFile::typeBinary | CFile::modeNoTruncate))