Sujet : Re: win32clipboard writing to clipboard on Windows 11
De : eryksun (at) *nospam* gmail.com (Eryk Sun)
Groupes : comp.lang.pythonDate : 18. Jun 2024, 09:26:39
Autres entêtes
Message-ID : <mailman.152.1718695638.2909.python-list@python.org>
References : 1 2 3 4
On Tue, Jun 18, 2024 at 2:19 AM Eryk Sun <
eryksun@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