Advertisement
Tkap1

Untitled

Apr 19th, 2024
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. func b8 set_clipboard(char* str)
  2. {
  3.     b8 result = false;
  4.     b8 close = false;
  5.     int len;
  6.     char* locked;
  7.     HGLOBAL mem;
  8.     HGLOBAL temp;
  9.  
  10.     if(!OpenClipboard(null)) { goto clipboard_end; }
  11.     close = true;
  12.     if(!EmptyClipboard()) { goto clipboard_end; }
  13.  
  14.     len = strleni(str);
  15.     mem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
  16.     locked = (char*)GlobalLock(mem);
  17.     memcpy(locked, str, len);
  18.     locked[len] = 0;
  19.     GlobalUnlock(mem);
  20.     if(!SetClipboardData(CF_TEXT, mem)) { goto clipboard_end; }
  21.     result = true;
  22.     temp = GlobalFree(mem);
  23.     assert(temp == null);
  24.  
  25. clipboard_end:
  26.     if(close) { CloseClipboard(); }
  27.     return result;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement