Skip to content

Commit 2939375

Browse files
committed
windows: fix readImageDib to check the handle, not stale GetLastError (#65)
readImageDib returned an error whenever GetLastError held a stale non-zero value (GetClipboardData does not reset it on success), so the CF_DIB fallback path bailed out and Read(FmtImage) returned nil for 24-bit images. Check the returned handle (hClipDat == 0) like readImage does.
1 parent b189b79 commit 2939375

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

clipboard_windows.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,12 @@ func readImageDib() ([]byte, error) {
164164
cFmtDIB = 8
165165
)
166166

167-
hClipDat, _, err := getClipboardData.Call(cFmtDIB)
168-
if err != nil {
169-
return nil, errors.New("not dib format data: " + err.Error())
167+
// Check the returned handle, not the syscall's lastErr: GetClipboardData
168+
// does not clear GetLastError on success, so err can hold a stale non-zero
169+
// value even when the format is present.
170+
hClipDat, _, _ := getClipboardData.Call(cFmtDIB)
171+
if hClipDat == 0 {
172+
return nil, errUnavailable
170173
}
171174
pMemBlk, _, err := gLock.Call(hClipDat)
172175
if pMemBlk == 0 {

0 commit comments

Comments
 (0)