Raggaer
Raggaer

Reputation: 3318

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?

Upvotes: 1

Views: 2148

Answers (1)

creker
creker

Reputation: 9570

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.

Upvotes: 3

Related Questions