In a Windows DLL that I'm accessing from Go one of the functions returns a 
wchar_t* containing some text. This comes back as a uintptr in r1. Here's 
my conversion function -- is it reasonable?

func CwcharToString(p uintptr) string {
    if p == 0 {
        return ""
    }
    uints := make([]uint16, 0, 65000) // Max chars accepted
    for p := uintptr(unsafe.Pointer(p)); ; p += 2 {
        u := *(*uint16)(unsafe.Pointer(p))
        if u == 0 {
            return string(utf16.Decode(uints))
        }
        uints = append(uints, u)
    }
}

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to