简体   繁体   中英

Go syscall call windows

Im currently trying to use user32.dll EnumWindows on Go but seems to not be working

var(
    user32 = syscall.NewLazyDLL("user32.dll")
    procEnumWindows = user32.NewProc("EnumWindows")
)

func EnumWindows() int {
    ret, _, _ := procEnumWindows.Call(
        syscall.NewCallback(enumWindowsProc),
        uintptr(0),
    )
    return int(ret)
}

func enumWindowsProc(hwnd syscall.Handle, lparam uintptr) bool {
    return true
}

Calling EnumWindows will give the following error:

panic: compileCallback: output parameter size is wrong

Im not sure how should I use the syscall package... I cant seem to find enough documentation on it

On the MSDN doc page it says that the callback should return a BOOL and thats what I am doing?

BOOL in WinAPI is declared as typedef int BOOL . So it doesn't match Go's bool . Specifications doesn't even mention what's the size it has. It's probably 1 byte but it doesn't say it. You should use int32 instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM