英文:
Go syscall call windows
问题
我目前正在尝试在Go语言中使用user32.dll的EnumWindows函数,但似乎无法正常工作。
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
}
调用EnumWindows函数会出现以下错误:
panic: compileCallback: output parameter size is wrong
我不确定应该如何使用syscall包... 我似乎找不到足够的文档。
在MSDN文档页面上,它说回调函数应该返回一个BOOL,而这正是我正在做的吗?
英文:
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?
答案1
得分: 3
BOOL
在WinAPI中被声明为typedef int BOOL
。所以它与Go语言的bool
类型不匹配。规范甚至没有提到它的大小是多少。它可能是1字节,但没有明确说明。你应该使用int32
代替。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论