• Welcome to Valhalla Legends Archive.
 

Clipboard copying and GlobalAlloc/Free

Started by iNsaNe, October 01, 2009, 11:34 PM

Previous topic - Next topic

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


        ...
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();
        ...

MyndFyre

Based on the MSDN article, it would seem to be dependent on the clipboard format chosen.

For CF_TEXT, yes, it should be freed.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.