CString to const char*

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi there,

I am having some really strange issues with the CString class...

For some reason it will not convert to const char* automatically, if I
try manually I just end up with a screwed up ASCII string still containing 0
bytes from the UNICODE equivilent.

char *pBuffer = new char[iString.GetLength()];
pBuffer = (char*)iString.GetBuffer(sizeof(pBuffer));
MessageBoxA(NULL, pBuffer, "", 0);

Strange thing is my CString class is within the WTL namespace, is there
more than one implementation of CString available?

What would be the best object to use for string handling, I thought this
class was okay but have read sources on the net that say std::string is
better...

Preferably I'd like to just use CString and convert it nicely... Thanks
loads in advance!

My application is UNICODE enabled. Thanks loads in advance.

Nick.


.



Relevant Pages

  • Re: CListBox::DrawItem code
    ... That's strange. ... I mean reusing CString is common, so why in case of that stupid cotrol it is ... I mean I pass some string using AddString. ... >> get a text from database and so is is not working. ...
    (microsoft.public.vc.mfc)
  • Re: CListBox::DrawItem code
    ... That's strange. ... >I mean reusing CString is common, so why in case of that stupid cotrol it is ... >> to read repeatedly from the database? ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Sorry - basic Q about using char[] instead of CString
    ... lpFUNCTION MyFunc(CString p1, CString p2, short* retVal, CString* retText) ... it sounds strange that you are passing CString's ...
    (microsoft.public.vc.mfc)
  • Re: CString seems to be full with a few lines of text..?
    ... The VC 6.0 debugger only shows the first 255 characters of a CString. ... It consists of \r\n terminated lines, ... behaviour is strange. ...
    (microsoft.public.win32.programmer.ui)
  • Re: Reentrancy issue
    ... Because of the change in the specification of the CString class, I will be changing to use ... the explicit cast. ... client code by removing the ==TRUE. ...
    (microsoft.public.vc.mfc)