golang win32編程的一個dll坑

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

例子

 

package mainimport ("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.HWNDcxScreen := 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() {// LibrarylibpdhDll = syscall.MustLoadDLL("pdh.dll")// Functionspdh_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,是個沒意思的事情!

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.