• golang win32编程的一个dll坑


    例子

    package main
    
    import (
    	"github.com/lxn/win"
    	"strconv"
    	"syscall"
    )
    
    func _TEXT(_str string) *uint16 {
    	return syscall.StringToUTF16Ptr(_str)
    }
    func _toString(_n int32) string {
    	return strconv.Itoa(int(_n))
    }
    func main() {
    	var hwnd win.HWND
    	cxScreen := win.GetSystemMetrics(win.SM_CXSCREEN)
    	cyScreen := win.GetSystemMetrics(win.SM_CYSCREEN)
    	win.MessageBox(hwnd, _TEXT("屏幕长-:"+_toString(cxScreen)+"宽:"+_toString(cyScreen)), _TEXT(" 消息"), win.MB_OK)
    }
    


    唯一的就是有一个win这个go module里有一个坑,在phd.go 中

    func init() {
    // Library
    libpdhDll = syscall.MustLoadDLL("pdh.dll")
    
    
    // Functions
    pdh_AddCounterW = libpdhDll.MustFindProc("PdhAddCounterW")
    pdh_AddEnglishCounterW = libpdhDll.MustFindProc("PdhAddEnglishCounterW") // XXX: only supported on versions > Vista.
    pdh_CloseQuery = libpdhDll.MustFindProc("PdhCloseQuery")
    pdh_CollectQueryData = libpdhDll.MustFindProc("PdhCollectQueryData")
    pdh_GetFormattedCounterValue = libpdhDll.MustFindProc("PdhGetFormattedCounterValue")
    pdh_GetFormattedCounterArrayW = libpdhDll.MustFindProc("PdhGetFormattedCounterArrayW")
    pdh_OpenQuery = libpdhDll.MustFindProc("PdhOpenQuery")
    pdh_ValidatePathW = libpdhDll.MustFindProc("PdhValidatePathW")
    }


    PdhAddEnglishCounterW这个api只在vista以上版本支持,所以如果在xp下运行,在载入时会因找不到该函数的地址崩溃,临时解决方案,暴力注释掉

    //pdh_AddEnglishCounterW = libpdhDll.MustFindProc("PdhAddEnglishCounterW") // XXX: only supported on versions > Vista.


    更丰富的例子:https://github.com/lxn/walk


    初步感觉用go写win gui,是个没意思的事情!

  • 相关阅读:
    每日日报
    每日日报
    flink入门到实战(2)flink优化总结
    flink入门到实战(1)入门学习
    机器学习算法一般步骤
    hadoop入门到实战(1)hive优化总结
    划重点|iOS15正式发布, 全新的通知推送系统,你必须要知道!
    云知声 Atlas 超算平台: 基于 Fluid + Alluxio 的计算加速实践
    终端卡顿优化的全记录
    云湖共生释放企业数据价值
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3290215.html
Copyright © 2020-2023  润新知