douxian8883 2016-02-12 19:30
浏览 403

Golang中的EnumChildWindows回调函数

Using package lxn/win in main:

win.EnumChildWindows(hw, printme, 0)

Then after main:

func printme(HWND win.HANDLE, LPARAM uintptr) { //HWND hwnd, LPARAM lParam
    spew.Dump(HWND)
}

I get:

.\test.go:40: cannot use printme (type func(win.HANDLE, uintptr)) as type uintptr in argument to win.EnumChildWindows

error:exit status 2

I don't understand the error message.

  • 写回答

1条回答 默认 最新

  • douzuo0711 2019-05-12 00:11
    关注

    I made it work with:

    win.EnumChildWindows(hwnd, syscall.NewCallback(printme), 0)
    
    func printme(hwnd uintptr, lParam uintptr) uintptr {
        spew.Dump(hwnd)
        fmt.Printf("getWindowText: '%s'
    ", getWindowText(hwnd))
        return 1 // true to continue
    }
    

    See lxn/win issue 19:

    The callback signature is wrong: it has to return a value of type int32 (C BOOL) that is nonzero if the function should continue enumeration.
    See MSDN.

    For example, it could be:

    func printme(hwnd uintptr, lParam uintptr) int32 {
        spew.Dump(hwnd)
        return 1 // true to continue
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看