Converting VS6 project to VS2008 - CString

In my VC6 project we have a class derived from CString called CString2.  It has a convenient method that loads a file.  Here is the code:

BOOL CString2::Load(FILE* stream, long bytes)
    size_t count = fread(m_pchData, sizeof(BYTE), bytes, stream);
    return ((long)count == bytes);

The problem that I'm having is that "AllocBuffer()" is no longer implement in 2005/2008.  Since this class is used in so many places within our code, for various reasons, I have been trying to come up with a way to replace the contents of the above method so as to not have to replace the entire class everywhere it's used.  I'm not that familiar with 2008 so any help would be GREAT!

Craig Schmidtsoftware EngineeringAsked:
Who is Participating?
Actually you need to reserve a memory block that will be big enough to load the file.
I think this file is a text (because you load it into a string class).
So, firstly CString has AllocSysString method, it's for BSTR and, I think, you can use it too.
Also CString has Insert method that allow you to insert any other string.
Also you can load the file into a WCHAR or char buffer and use the CString assignment operator to store the data into your class.

The correct way was to make a helper class, simply a function, that load the data from the file into a buffer (or into your class).

Pay attention on GetBuffer and Release
Craig Schmidtsoftware EngineeringAuthor Commented:
Thanks pgnatyuk.  I'll give your suggestions a try.

You are welcome
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.