We help IT Professionals succeed at work.

large CString problem

rileo8 asked
I have a custom resource that contains a html file of 32KB.

I need to:

- copy it into a Cstring
- replace some characters
- save it to a file

But i'm experiencing some problems because seems thata only a part of the html file is saved into the CString...

what's wrong???
Watch Question

Hi rileo8,

IMO this shouldn't be a problem with the size of the CString - I think a CString's length can be (theoretically) MAX_INT - 1.

I guess the problem is somewhere else in your code - could you post the code you're using?

Top Expert 2016

your last question about reading the html resource was not yet closed. did you come further?

you seemed to have used code from http://www.codeproject.com/KB/cpp/GetHTML.aspx and it is not quite clear whether your current question is related to that.  

check your project properties whether there is UNICODE enabled or not. if it is enabled the CString is based on WCHAR (== wchar_t) type what is a two-byte "wide" character. if you have "Multibyte Character Set" enabled, the CString is based on char type.

if you read the resource with LoadResource and get a pointer by LockResource, the pointer needs to be casted to LPCTSTR what is 'long constant pointer to TCHAR string', what means that it also either points to wide char buffer (UNICODE) or char buffer (Multibyte).

the code from codeproject is already considering that.

how much data did you get from the html file? is it possible that the html contains some binary data? the problem with that might be that binary data likely contains binary zero characters which are regarded as terminators when you assign them to a CString. so a statement like

rString = CString(lpcHtml);

Open in new window

would fail in determining the correct length of the html if it contains zero characters. if that could be the case you need to change the html before you can read it into a CString.

another idea that came to my mind is that the CString could contain linefeed characters and because of that you only see parts of the html in the debugger. try to use AfxMessageBox or OutputDebugString to show the CString. that would correctly show a multi-line string.

Do you have a code sample that you can post, so we can see how you are doing it.