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)
{
    ASSERT(stream);
    Empty();
    AllocBuffer(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!

Thanks
Craig Schmidtsoftware EngineeringAsked:
Who is Participating?
 
pgnatyukCommented:
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.
http://msdn.microsoft.com/en-US/library/za1865s1(v=VS.80).aspx
Also CString has Insert method that allow you to insert any other string.
http://msdn.microsoft.com/en-US/library/t4az6wc0(v=VS.80).aspx
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).
0
 
pgnatyukCommented:
http://msdn.microsoft.com/en-us/library/awkwbzyc(VS.80).aspx

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

Craig
0
 
pgnatyukCommented:
You are welcome
0
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.