Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clipboard_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package clipboard

import (
"errors"
"runtime"
"syscall"
"time"
Expand All @@ -33,6 +34,8 @@ var (
globalLock = kernel32.NewProc("GlobalLock")
globalUnlock = kernel32.NewProc("GlobalUnlock")
lstrcpy = kernel32.NewProc("lstrcpyW")

ErrFormatUnavailable = errors.New("clipboard format is unavailable")
)

// waitOpenClipboard opens the clipboard, waiting for up to a second to do so.
Expand All @@ -56,8 +59,8 @@ func readAll() (string, error) {
// Otherwise if the goroutine switch thread during execution (which is a common practice), the OpenClipboard and CloseClipboard will happen on two different threads, and it will result in a clipboard deadlock.
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if formatAvailable, _, err := isClipboardFormatAvailable.Call(cfUnicodetext); formatAvailable == 0 {
return "", err
if formatAvailable, _, _ := isClipboardFormatAvailable.Call(cfUnicodetext); formatAvailable == 0 {
return "", ErrFormatUnavailable
}
err := waitOpenClipboard()
if err != nil {
Expand Down