Re: SetClipBoardData CF_RTF problem
"Anu" <anu.mishra@gmail.com> wrote in message
news:1172658961.715239.169320@k78g2000cwa.googlegroups.com...
HI,
I am using the following code to copy the text to clipboard. When I
set the format to CF_TEXT, it works fine but with CF_RTF, I get an
extra chracter "_" (underscore) in the string. Can someone help me
here?
if(OpenClipboard(NULL))
{
EmptyClipboard();
HGLOBAL hglbCopy=GlobalAlloc(GMEM_MOVEABLE,
(length+1) * sizeof(TCHAR));
if(hglbCopy != NULL)
{
// Lock the handle and copy the text to the buffer.
LPTSTR lptstrCopy = (LPTSTR)GlobalLock(hglbCopy);
memcpy(lptstrCopy, str.GetBuffer(0), length * sizeof(TCHAR));
lptstrCopy[length] = (TCHAR) 0; // null character
GlobalUnlock(hglbCopy);
// Place the handle on the clipboard.
UINT hRTF = RegisterClipboardFormat(CF_RTF); //("Rich Text Format")
SetClipboardData(hRTF,hglbCopy);
CloseClipboard();
I guess "str" is the RTF data and "length" is the number of characters of
"str"?
Does the extra "_" appear at the end?
Run this in the debugger, and make sure lpstrCopy is set to the right thing.
Are you sure you need to add an extra NULL after the "str"?
-- David (MVP)