3

On the official Microsoft docs for EmptyClipboard, it says that EmptyClipboard should cause SetClipboardData to fail when a NULL window handle is used for OpenClipboard. However this doesn't seem to be the case at all, so what's going on? In fact, SetClipboardData doesn't work when I don't call EmptyClipboard, and every stackoverflow post on it says to call EmptyClipboard before SetClipboardData.

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-emptyclipboard (Under Remarks)

Before calling EmptyClipboard, an application must open the clipboard by using the OpenClipboard function. If the application specifies a NULL window handle when opening the clipboard, EmptyClipboard succeeds but sets the clipboard owner to NULL. Note that this causes SetClipboardData to fail.

Many stackoverflow posts saying to do exactly what Microsoft says should fail (with success!):

How to copy bitmap to clipboard using the win32 API?

How to copy string to clipboard in C?

Chris
  • 26,361
  • 5
  • 21
  • 42
PerthGoat
  • 31
  • 1
  • 1
    ***SetClipboardData doesn't work when I don't call EmptyClipboard*** what do you mean by "doesn't work"? What happens - do you get any errors? – kiner_shah Dec 09 '21 at 03:33
  • 3
    The system doesn't behave as documented. This has been asked previously, but I'm unable to find the question. Maybe its author decided to delete it after it received lots of downvotes. – IInspectable Dec 09 '21 at 07:10
  • 2
    Indeed, something's not right here. My findings (Windows 10) show that "Open(anything)+Set+Close" works (if you don't need render messages) Empty being optional. Thinking about it it and the semantics of an end-user "copy action" (put one thing in the clipboard), it sounds it should work like that and it does.... so where's the truth? See also this https://devblogs.microsoft.com/oldnewthing/20210526-00/?p=105252 which doesn't help us much for once – Simon Mourier Dec 09 '21 at 08:23

0 Answers0