win32clipboard writing to clipboard on Windows 11
Eryk Sun
eryksun at gmail.com
Tue Jun 18 03:26:39 EDT 2024
On Tue, Jun 18, 2024 at 2:19 AM Eryk Sun <eryksun at gmail.com> wrote:
>
>
> def set_clipboard_text(text):
> hMem = global_alloc_text(text)
> try:
> win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
> hMem)
> # Now the system owns the global memory.
> except:
> kernel32.GlobalFree(hMem)
Oops, that suppresses the exception. Fixed:
def set_clipboard_text(text):
hMem = global_alloc_from_text(text)
try:
win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
hMem)
# Now the system owns the global memory.
except:
kernel32.GlobalFree(hMem)
raise
More information about the Python-list
mailing list