Ik gebruik de volgende code om een string naar het clipboard kopieeren.
Nu is mijn vraag, moet ik na SetClipboardData nog GlobalFree aanroepen?
MSDN zegt:
Nu is mijn vraag, moet ik na SetClipboardData nog GlobalFree aanroepen?
MSDN zegt:
Als ik het wel doe werkt de functie niet meer, maar als ik het niet doe, lek ik toch een handle?After SetClipboardData is called, the system owns the object identified by the hMem parameter. The application can read the data, but must not free the handle or leave it locked until the CloseClipboard function is called. (The application can access the data after calling CloseClipboard). If the hMem parameter identifies a memory object, the object must have been allocated using the function with the GMEM_MOVEABLE flag.
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| void CXBTClientDlg::set_clipboard(const string& v) { if (v.empty()) return; void* h = GlobalAlloc(GMEM_MOVEABLE, v.size() + 1); void* p = GlobalLock(h); if (p) { memcpy(p, v.c_str(), v.size() + 1); GlobalUnlock(h); if (OpenClipboard()) { EmptyClipboard(); SetClipboardData(CF_TEXT, h); CloseClipboard(); return; } } GlobalFree(h); } |