The cgo.wchar package is to be used with go/cgo and helps with the conversion from and to C.wchar_t and wchar_t strings (*C.wchar_t with null terminator or length int).
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 6 commits ahead of GeertJohan:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
convert.go
readme.md
wchar.go
wchar_notwin.go
wchar_test.go
wchar_windows.go

readme.md

cgo.wchar

Helps with using wchars with cgo.

Example

Example from the go.hid library:

func (dev *Device) ManufacturerString() (string, error) {
	// create WcharString
	ws := wchar.NewWcharString(100)

	// retrieve manufacturer string from hid
	res := C.hid_get_manufacturer_string(dev.hidHandle, (*C.wchar_t)(ws.Pointer()), 100)
	if res != 0 {
		return "", dev.lastError()
	}

	// get WcharString as Go string
	str := ws.GoString()

	// all done
	return str, nil
}