golang win32编程的一个dll坑

songbohr · · 1302 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

例子

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(" 消息http://blog.csdn.net/songbohr"), 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,是个没意思的事!


后记:刚才搜了下baidu,转载的都没注明出处。。。。oh,shit!


有疑问加站长微信联系(非本文作者)

本文来自:CSDN博客

感谢作者:songbohr

查看原文:golang win32编程的一个dll坑

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1302 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传