clipboard icon indicating copy to clipboard operation
clipboard copied to clipboard

Windows 32-bit system will get stuck when executing.

Open c17abab opened this issue 1 year ago • 3 comments

The compilation parameters are as follows: $env:GOARCH="amd64"; $env:GOOS="windows"; $env:GOARCH="386"; # 32 #$env:GOARCH="amd64"; # 64

and the program will be stucked at line 324 in the file clipborad_windows.go:

println("test in read 2")
// try again until open clipboard successed
   // will stuck here
for {
	r, _, _ = openClipboard.Call()
	if r == 0 {
		continue
	}
	break
}
    //  the following code will not be executed.
println("test in read 3")

c17abab avatar Apr 12 '23 02:04 c17abab

Good point. Is there any specific use case for 32-bit windows? I am 99% sure that this package didn't consider 32-bit windows.

changkun avatar Apr 12 '23 06:04 changkun

Good point. Is there any specific use case for 32-bit windows? I am 99% sure that this package didn't consider 32-bit windows.

Found the cause of the problem, the user32.dll function openClipboard need a parameter(A handle to the window to be associated with the open clipboard. If this parameter is NULL, the open clipboard is associated with the current task). So maybe you need to get the window handle first, or set the parameter to 0: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-openclipboard

eg:


	// Here you need to get the handle of the clipboard window first
	getOpenClipboardWindow := user32.MustFindProc("GetOpenClipboardWindow")
	for {
		r, _, _ = getOpenClipboardWindow.Call()
                // set the parameter to 0 is also ok
		r, _, _ = openClipboard.Call(r)
		if r == 0 {
			continue
		}
		break
	}
	defer closeClipboard.Call()

c17abab avatar Apr 12 '23 07:04 c17abab

Thanks for the investigation. As you already investigated the issue, any PR would be very welcome 👍

changkun avatar Apr 12 '23 07:04 changkun