Craig Schmidt
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks pgnatyuk. I'll give your suggestions a try.
Craig
Craig
You are welcome
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).