If you look at MFC/server/LogI.cpp you'll find:
Code:
void
LogI::post(const string& data)
{
assert(_hwnd != 0);
char* text = new char[data.size()+1];
strcpy(text, data.c_str());
::PostMessage(_hwnd, WM_USER, (WPARAM)FALSE, (LPARAM)text);
}
When this message is received the text is added to the text control, and then the memory freed.
Code:
LRESULT
CHelloServerDlg::OnLog(WPARAM wParam, LPARAM lParam)
{
char* text = (char*)lParam;
_edit->SetSel(-1, -1);
_edit->ReplaceSel(CString(text));
delete[] text;
return 0;
}
You can use a similar approach in your application. In this case, a reference counted type is not necessary since the data is received by only a single recipient. If you have multiple recipients, or possibly no recipient then you'd need to take a different approach.