Valhalla Legends Forums Archive | C/C++ Programming | Clipboard copying and GlobalAlloc/Free

AuthorMessageTime
iNsaNe
I have a program where the user can copy text to the clipboard by clicking a drop down menu item.

My question is, does a call to EmptyClipboard free the data previously allocated with the call to GlobalAlloc? Or do i need to free the data with GlobalFree? I dont want to create memory leaks.

this is my code

[code]
        ...
BYTE size = strPath.size() + 1;
char *pText = (char *)GlobalAlloc(GMEM_FIXED, size);

strcpy(pText, strPath.c_str());
OpenClipboard(hWnd);
EmptyClipboard();
SetClipboardData(CF_TEXT, pText);
CloseClipboard();
        ...
[/code]
October 2, 2009, 4:34 AM
Myndfyr
Based on the MSDN article, it would seem to be dependent on the clipboard format chosen.

For CF_TEXT, yes, it should be freed.
October 4, 2009, 9:57 AM

Search