Golang Win32 programming a DLL Pit

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Example

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 ("screen length-:" +_tostring (Cxscreen) + "width:" +_tostring (Cyscreen)), _text ("Message http://blog.csdn.net/ Songbohr "), win. MB_OK)}


The only thing that is there is a win this go module has a pit in the 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 This API is only supported in Vista or above, so if you run under XP, the address of the function will crash when it is loaded, temporary solution, violence comment out

Pdh_addenglishcounterw = Libpdhdll.mustfindproc ("pdhaddenglishcounterw")//Xxx:only supported on versions > Vista .


A richer example: Https://github.com/lxn/walk


Initial feeling with Go write win GUI, is a boring thing!


PostScript: Just searched the next Baidu, reproduced all did not indicate the source .... oh,shit!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.