title: IPC through windows clipboard using c++
body: <p>This is how you can get last text item from clipboard:</p>
  <pre><code>OpenClipboard(nullptr);
  
      HANDLE hData = GetClipboardData(CF_TEXT);
  
      char* pszText = static_cast&lt;char*&gt;(GlobalLock(hData));
  
      std::string text;
      if (pszText != nullptr)
      {
          text.assign(pszText);
      }
  
      GlobalUnlock(hData);
  
      CloseClipboard();
  
      std::cout &lt;&lt; text;
  </code></pre>
  <p>This is how you can set an text item from clipboard:</p>
  <pre><code>std::string source(&quot;text&quot;);
      if (OpenClipboard(nullptr))
      {
          HGLOBAL clipbuffer;
          char* buffer;
          EmptyClipboard();
          clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.length() + 1);
          buffer = (char*)GlobalLock(clipbuffer);
          strcpy(buffer, source.c_str());
          GlobalUnlock(clipbuffer);
          SetClipboardData(CF_TEXT, clipbuffer);
          CloseClipboard();
      }
  </code></pre>
  <p>But I don't know how to delete last text item from clipboard, I would like to be able to not let the user see that I am using the clipboard or change his clipboard so he cant paste last thing he copied...</p>
  <p>How can I do this, delete an text item from windows clipboard using c++ ?</p>