Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func b8 set_clipboard(char* str)
- {
- b8 result = false;
- b8 close = false;
- int len;
- char* locked;
- HGLOBAL mem;
- HGLOBAL temp;
- if(!OpenClipboard(null)) { goto clipboard_end; }
- close = true;
- if(!EmptyClipboard()) { goto clipboard_end; }
- len = strleni(str);
- mem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
- locked = (char*)GlobalLock(mem);
- memcpy(locked, str, len);
- locked[len] = 0;
- GlobalUnlock(mem);
- if(!SetClipboardData(CF_TEXT, mem)) { goto clipboard_end; }
- result = true;
- temp = GlobalFree(mem);
- assert(temp == null);
- clipboard_end:
- if(close) { CloseClipboard(); }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement