From d8ee23ff740d80ad365bc6eb4b32ce3100198e8f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 3 Jun 2014 02:06:11 -0400 Subject: [PATCH] Added convenience functions to the Windows backend for UTF-16 string handling. I'll convert the existing code to use it shortly. --- common_windows.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common_windows.go b/common_windows.go index 2a403c7..2c1c3fd 100644 --- a/common_windows.go +++ b/common_windows.go @@ -71,6 +71,18 @@ func negConst(c int) uintptr { return uintptr(c) } +// the next two are convenience wrappers +// the intention is not to say utf16ToArg(toUTF16(s)) - even though it appears to work fine, that's just because the garbage collector is slow; if we store this globally then things will break +// instead, call them separately - s := toUTF16(str); winapifunc.Call(utf16ToArg(s)) + +func toUTF16(s string) *uint16 { + return syscall.StringToUTF16Ptr(s) +} + +func utf16ToArg(s *uint16) uintptr { + return uintptr(unsafe.Pointer(s)) +} + var ( _adjustWindowRectEx = user32.NewProc("AdjustWindowRectEx") _createWindowEx = user32.NewProc("CreateWindowExW")