Skip to content

Instantly share code, notes, and snippets.

@hymkor
Last active August 29, 2015 14:09
Show Gist options
  • Save hymkor/f90f4c5d349e734e2e7b to your computer and use it in GitHub Desktop.
Save hymkor/f90f4c5d349e734e2e7b to your computer and use it in GitHub Desktop.
[go] cgoは使いたくないけど、C.GoBytes() は使いたいみたいなー [追記あり] ref: http://qiita.com/zetamatta/items/eb233ad17c15b31b2359
var msvcrt = syscall.NewLazyDLL("msvcrt")
var memcpy = msvcrt.NewProc("memcpy")
func CGoBytes(p, length uintptr) []byte {
buffer := make([]byte, length)
memcpy.Call(uintptr(unsafe.Pointer(&buffer[0])), p, length)
return buffer
}
func CGoStringN(p, length uintptr) string {
return string(CGoBytes(p, length))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment