Go에서 dll 샘플 호출

826 단어 go
package main 

import (
  "syscall"
)

func main(){
	h, err := syscall.LoadLibrary("kernel32.dll")
	if err != nil {
	  abort("LoadLibrary", err)
	}
  defer syscall.FreeLibrary(h)
  proc, err := syscall.GetProcAddress(h, "GetVersion")
  if err != nil {
    abort("GetProcAddress", err)
  }
  r, _, _ := syscall.Syscall(uintptr(proc), 0, 0, 0, 0)
  print_version(uint32(r))
}

func abort(funcname string, err error) {
  panic(funcname + " failed: " + err.Error())
}

func print_version(v uint32) {
	major := byte(v)
	minor := uint8(v >> 8)
	build := uint16(v >> 16)
	print("windows version ", major, ".", minor, " (Build ", build, ")
") }

다음으로 이동:http://bbs.studygolang.com/thread-277-1-1.html


좋은 웹페이지 즐겨찾기