参考:https://studygolang.com/articles/2712

package main

import (
    "syscall"
    "time"
    "unsafe"
)

func IntPtr(n int) uintptr {
    return uintptr(n)
}

func StrPtr(s string) uintptr {
    return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
}

// windows下的另一种DLL方法调用
func ShowMessage2(title, text string) {
    user32dll, _ := syscall.LoadLibrary("user32.dll")
    user32 := syscall.NewLazyDLL("user32.dll")
    MessageBoxW := user32.NewProc("MessageBoxW")
    MessageBoxW.Call(IntPtr(0), StrPtr(text), StrPtr(title), IntPtr(0))
    defer syscall.FreeLibrary(user32dll)
}

func main() {
    go func() {
        for {
            ShowMessage2("windows下的另一种DLL方法调用", "HELLO !")
            time.Sleep(3 * time.Second)
        }
    }()
    select {}
}

 

相关文章:

  • 2021-08-23
  • 2021-11-29
  • 2021-12-30
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-29
  • 2021-08-17
  • 2022-12-23
  • 2021-04-02
  • 2021-07-03
  • 2021-12-27
相关资源
相似解决方案