Go win32

先说的让人兴奋的吧,“GO的库开发在windwos上尽然是一摸一样的啊”

C:\go-pro\go-self-package>go build gin-main.go

2017/09/20 14:39 1,936,384 gin-main.exe
2017/09/20 14:35 89 gin-main.go
2 个文件 1,936,473 字节
2 个目录 261,820,047,360 可用字节

C:\go-pro\go-self-package>gin-main.exe
1 is ok
2 is ok

这就是我为什么坚持GO的原因,名厂名牌,就是不一样啊,比那个WebAssembly强啊!!!!

为什么这么说呢,因为,我们伟大的GO尽然可以调用win32系统函数啊!!!!!

哇,哈哈哈,这不是强一点儿,是上了天啊!!!!!!

windows前端的兄弟姐妹们,我们开GO吧

一 DEMO

//win.go 显示磁盘剩余空间,win32系统函数"Kernel32.dll"=>"GetDiskFreeSpaceExW"

import (
  "syscall"
  "unsafe"
  "log"
)

func main() {

  kernel32, _ := syscall.LoadLibrary("Kernel32.dll")
  defer syscall.FreeLibrary(kernel32)
  GetDiskFreeSpaceEx, _ := syscall.GetProcAddress(syscall.Handle(kernel32), "GetDiskFreeSpaceExW")

  lpFreeBytesAvailable := int64(0)
  lpTotalNumberOfBytes := int64(0)
  lpTotalNumberOfFreeBytes := int64(0)

  r, _, _ := syscall.Syscall6(uintptr(GetDiskFreeSpaceEx), 4,
        uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("F:"))),
        uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
        uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
        uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)), 0, 0)

  if 0!=r {
  log.Printf("Free %dmb", lpTotalNumberOfFreeBytes/1024/1024)
  }
}

//运行

go build win.go

C:\go-pro\go-win32>win.exe
2017/09/20 14:48:55 Free 257812mb

看到没有,无与伦比啊,哈哈哈

Finally:

如此美妙,大家真的可以认真考虑一下,把GO跑到windows下了。

前途无量!!!!

上一篇:delphi ole word


下一篇:一个IP每天只弹一次广告窗口