-3

In C++ how to read text from the clipboard and how to write text to the clipboard?

Reading and writing only bare text: Text properties like font, color, ... are ignored. If there is something else in the clipboard, the string that receives the clipboard content stays empty.

What library? What function?

Inherent
  • 183
  • 1
  • 1
  • 13
  • 1
    Recommendation: Take a shot at writing your own solution to the is problem. If you get stuck and have exhausted your debugging options, that's when you ask a question on Stack Overflow. – user4581301 May 02 '22 at 20:12
  • 2
    Have you read MSDN's documentation about the [Clipboard](https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard) yet? Specifically, use the [`OpenClipboard()`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-openclipboard), [`GetClipboardData()`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboarddata) and [`SetClipboardData()`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setclipboarddata) functions. Not that hard to figure out. – Remy Lebeau May 02 '22 at 20:44
  • Yes, but I don't understand how to read text from the clipboard and wirte text to the clipboard with these functions. All these functions don't work with a string and text is in a string. – Inherent May 03 '22 at 07:28

1 Answers1

0

It seems that in C++ it is impossible to read and write text from & to the clipboard. Nobody knows how to do it. Nobody can answer my question.

--> I uninstalled the C++ compiler and created the tiny program in Python with pyperclip:

pip install pyperclip
import pyperclip as clipboard
string = clipboard.paste()  # get text from clipboard
clipboard.copy(string)      # writes text to clipboard

Really easy in Python, impossible in C++

Inherent
  • 183
  • 1
  • 1
  • 13