Skip to content

Commit 0645427

Browse files
authoredOct 24, 2022
[InteractiveUtils] win: handle empty clipboard errors (#47311)
Fix #46981
1 parent 0c382c2 commit 0645427

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎stdlib/InteractiveUtils/src/clipboard.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ elseif Sys.iswindows()
103103
ccall(:memcpy, Ptr{UInt16}, (Ptr{UInt16}, Ptr{UInt16}, Csize_t), plock, x_u16, sizeof(x_u16))
104104
unlock = ccall((:GlobalUnlock, "kernel32"), stdcall, Cint, (Ptr{UInt16},), pdata)
105105
(unlock == 0 && Libc.GetLastError() == 0) || return cleanup(:GlobalUnlock) # this should never fail
106-
pset = ccall((:SetClipboardData, "user32"), stdcall, Ptr{UInt16}, (Cuint, Ptr{UInt16}), 13, pdata)
106+
pset = ccall((:SetClipboardData, "user32"), stdcall, Ptr{UInt16}, (Cuint, Ptr{UInt16}), 13, pdata) # CF_UNICODETEXT
107107
pdata != pset && return cleanup(:SetClipboardData)
108108
cleanup(:success)
109109
end
@@ -114,14 +114,14 @@ elseif Sys.iswindows()
114114
if cause !== :OpenClipboard
115115
ccall((:CloseClipboard, "user32"), stdcall, Cint, ()) == 0 && Base.windowserror(:CloseClipboard) # this should never fail
116116
end
117-
if cause !== :success && (cause !== :GetClipboardData || errno != 0)
117+
if cause !== :success && !(cause === :GetClipboardData && (errno == 0x8004006A || errno == 0x800401D3)) # ignore DV_E_CLIPFORMAT and CLIPBRD_E_BAD_DATA from GetClipboardData
118118
Base.windowserror(cause, errno)
119119
end
120120
""
121121
end
122122
ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL) == 0 && return Base.windowserror(:OpenClipboard)
123123
ccall(:SetLastError, stdcall, Cvoid, (UInt32,), 0) # allow distinguishing if the clipboard simply didn't have text
124-
pdata = ccall((:GetClipboardData, "user32"), stdcall, Ptr{UInt16}, (Cuint,), 13)
124+
pdata = ccall((:GetClipboardData, "user32"), stdcall, Ptr{UInt16}, (Cuint,), 13) # CF_UNICODETEXT
125125
pdata == C_NULL && return cleanup(:GetClipboardData)
126126
plock = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{UInt16}, (Ptr{UInt16},), pdata)
127127
plock == C_NULL && return cleanup(:GlobalLock)

0 commit comments

Comments
 (0)
Please sign in to comment.