Last active
August 29, 2015 14:09
-
-
Save hymkor/f90f4c5d349e734e2e7b to your computer and use it in GitHub Desktop.
[go] cgoは使いたくないけど、C.GoBytes() は使いたいみたいなー [追記あり] ref: http://qiita.com/zetamatta/items/eb233ad17c15b31b2359
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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