Re: CString help

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



First, you are likely reading my essay.

So why would you need to call CString::GetBuffer in a MessageBox call? There's no useful
purpose served by doing that. In fact, you should be doing
AfxMessageBox(cString, MB_OK);

Microsoft guidelines say the title should be the name of the program, so there is no
reason to use a different title. There is no reason to use m_hWnd since there is already
a CWnd::MessageBox call, so you would write
MessageBox(cString, lpTitle, MBOK);

So your complaint is that you are doing something unnecessary?
joe

On Thu, 21 Jun 2007 14:17:04 -0500, "jp2code" <poojo.com/mail> wrote:

I'm looking at a website on CString Management:

http://www.codeproject.com:80/string/cstringmgmt.asp

In the section entitled, "CString to char * II: Using GetBuffer," the author
stresses calling ReleaseBuffer after calling GetBuffer.

Is this always necessary?

I often use CString::GetBuffer when using CStrings in MessageBox dialogs
like so:

MessageBox(m_hWnd, cString.GetBuffer(0), lpTitle, MB_OK);

Should I be adding a ReleaseBuffer after a MessageBox call?

Should I be passing my string data to the MessageBox in another way?

Regards,
Joe

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Debug Multithreaded DLL and Multithreaded DLL
    ... Thanks Joe. ... I think what you suggested about timing issue could be correct, ... I've introduced a MessageBox before the fstream->read call, ... when I run it (this is basically the reason why I called it a runtime ...
    (microsoft.public.vc.mfc)
  • Re: migration vc6.0 -> vc8.0
    ... So have I, including a MessageBox that contained ONLY the error icon (no text, no ... caption). ... But I suspect that this is NOT what actually happened in this case. ...
    (microsoft.public.vc.mfc)
  • Re: Hiding Messagebox in CEditView
    ... If it wasn't read only then overriding CanCloseFrame or SaveModified would ...    if ... But I dont want this messagebox to popup ..... ...
    (microsoft.public.vc.mfc)
  • Re: GetSysColors
    ... to a messagebox. ... however, COLOR_WINDOW is incorrect. ... NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth ...
    (microsoft.public.vc.mfc)
  • CString help
    ... I'm looking at a website on CString Management: ... stresses calling ReleaseBuffer after calling GetBuffer. ... Should I be adding a ReleaseBuffer after a MessageBox call? ...
    (microsoft.public.vc.mfc)