本文整理汇总了Golang中syscall.StringToUTF16函数的典型用法代码示例。如果您正苦于以下问题:Golang StringToUTF16函数的具体用法?Golang StringToUTF16怎么用?Golang StringToUTF16使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringToUTF16函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getTuntapComponentId
func getTuntapComponentId() (string, error) {
adapters, err := registry.OpenKey(registry.LOCAL_MACHINE, ADAPTER_KEY, registry.READ)
if err != nil {
return "", err
}
var i uint32
for ; i < 1000; i++ {
var name_length uint32 = TAPWIN32_MAX_REG_SIZE
buf := make([]uint16, name_length)
if err = syscall.RegEnumKeyEx(
syscall.Handle(adapters),
i,
&buf[0],
&name_length,
nil,
nil,
nil,
nil); err != nil {
return "", err
}
key_name := syscall.UTF16ToString(buf[:])
adapter, err := registry.OpenKey(adapters, key_name, registry.READ)
if err != nil {
return "", err
}
name := syscall.StringToUTF16("ComponentId")
name2 := syscall.StringToUTF16("NetCfgInstanceId")
var valtype uint32
var component_id = make([]byte, TAPWIN32_MAX_REG_SIZE)
var componentLen = uint32(len(component_id))
if err = syscall.RegQueryValueEx(
syscall.Handle(adapter),
&name[0],
nil,
&valtype,
&component_id[0],
&componentLen); err != nil {
return "", err
}
if unicodeTostring(component_id) == TUNTAP_COMPONENT_ID {
var valtype uint32
var netCfgInstanceId = make([]byte, TAPWIN32_MAX_REG_SIZE)
var netCfgInstanceIdLen = uint32(len(netCfgInstanceId))
if err = syscall.RegQueryValueEx(
syscall.Handle(adapter),
&name2[0],
nil,
&valtype,
&netCfgInstanceId[0],
&netCfgInstanceIdLen); err != nil {
return "", err
}
fmt.Println("Device:", unicodeTostring(netCfgInstanceId))
return unicodeTostring(netCfgInstanceId), nil
}
}
return "", errors.New("not found component id")
}
示例2: StartDocument
func (p *Printer) StartDocument(name, datatype string) error {
d := DOC_INFO_1{
DocName: &(syscall.StringToUTF16(name))[0],
OutputFile: nil,
Datatype: &(syscall.StringToUTF16(datatype))[0],
}
return StartDocPrinter(p.h, 1, &d)
}
示例3: showMessage
func (ni *NotifyIcon) showMessage(title, info string, iconType uint32) error {
nid := ni.notifyIconData()
nid.UFlags = NIF_INFO
nid.DwInfoFlags = iconType
copy(nid.SzInfoTitle[:], syscall.StringToUTF16(title))
copy(nid.SzInfo[:], syscall.StringToUTF16(info))
if !Shell_NotifyIcon(NIM_MODIFY, nid) {
return newError("Shell_NotifyIcon")
}
return nil
}
示例4: createForDPI
func (this *Font) createForDPI(dpi int) w32.HFONT {
var lf w32.LOGFONT
lf.Height = -w32.MulDiv(this.pointSize, dpi, 72)
if this.style&FontBold > 0 {
lf.Weight = w32.FW_BOLD
} else {
lf.Weight = w32.FW_NORMAL
}
if this.style&FontItalic > 0 {
lf.Italic = 1
}
if this.style&FontUnderline > 0 {
lf.Underline = 1
}
if this.style&FontStrikeOut > 0 {
lf.StrikeOut = 1
}
lf.CharSet = w32.DEFAULT_CHARSET
lf.OutPrecision = w32.OUT_TT_PRECIS
lf.ClipPrecision = w32.CLIP_DEFAULT_PRECIS
lf.Quality = w32.CLEARTYPE_QUALITY
lf.PitchAndFamily = w32.VARIABLE_PITCH | w32.FF_SWISS
src := syscall.StringToUTF16(this.family)
dest := lf.FaceName[:]
copy(dest, src)
return w32.CreateFontIndirect(&lf)
}
示例5: setString
func (k *Key) setString(name string, value string, valtype uint32) error {
buf := syscall.StringToUTF16(value)
return winapi.RegSetValueEx(
k.Handle, syscall.StringToUTF16Ptr(name),
0, valtype,
(*byte)(unsafe.Pointer(&buf[0])), uint32(len(buf)*2))
}
示例6: createForDPI
func (f *Font) createForDPI(dpi int) HFONT {
var lf LOGFONT
lf.LfHeight = -MulDiv(int32(f.pointSize), int32(dpi), 72)
if f.style&FontBold > 0 {
lf.LfWeight = FW_BOLD
} else {
lf.LfWeight = FW_NORMAL
}
if f.style&FontItalic > 0 {
lf.LfItalic = 1
}
if f.style&FontUnderline > 0 {
lf.LfUnderline = 1
}
if f.style&FontStrikeOut > 0 {
lf.LfStrikeOut = 1
}
lf.LfCharSet = DEFAULT_CHARSET
lf.LfOutPrecision = OUT_TT_PRECIS
lf.LfClipPrecision = CLIP_DEFAULT_PRECIS
lf.LfQuality = CLEARTYPE_QUALITY
lf.LfPitchAndFamily = VARIABLE_PITCH | FF_SWISS
src := syscall.StringToUTF16(f.family)
dest := lf.LfFaceName[:]
copy(dest, src)
return CreateFontIndirect(&lf)
}
示例7: Remove
// Remove removes the named file or directory.
// If there is an error, it will be of type *PathError.
func Remove(name string) error {
p := &syscall.StringToUTF16(name)[0]
// Go file interface forces us to know whether
// name is a file or directory. Try both.
e := syscall.DeleteFile(p)
if e == nil {
return nil
}
e1 := syscall.RemoveDirectory(p)
if e1 == nil {
return nil
}
// Both failed: figure out which error to return.
if e1 != e {
a, e2 := syscall.GetFileAttributes(p)
if e2 != nil {
e = e2
} else {
if a&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
e = e1
}
}
}
return &PathError{"remove", name, e}
}
示例8: calculateTextSizeImpl
func (wb *WidgetBase) calculateTextSizeImpl(text string) Size {
hdc := GetDC(wb.hWnd)
if hdc == 0 {
newError("GetDC failed")
return Size{}
}
defer ReleaseDC(wb.hWnd, hdc)
hFontOld := SelectObject(hdc, HGDIOBJ(wb.Font().handleForDPI(0)))
defer SelectObject(hdc, hFontOld)
var size Size
lines := strings.Split(text, "\n")
for _, line := range lines {
var s SIZE
str := syscall.StringToUTF16(strings.TrimRight(line, "\r "))
if !GetTextExtentPoint32(hdc, &str[0], int32(len(str)-1), &s) {
newError("GetTextExtentPoint32 failed")
return Size{}
}
size.Width = maxi(size.Width, int(s.CX))
size.Height += int(s.CY)
}
return size
}
示例9: calculateMaxItemTextWidth
func (lb *ListBox) calculateMaxItemTextWidth() int {
hdc := win.GetDC(lb.hWnd)
if hdc == 0 {
newError("GetDC failed")
return -1
}
defer win.ReleaseDC(lb.hWnd, hdc)
hFontOld := win.SelectObject(hdc, win.HGDIOBJ(lb.Font().handleForDPI(0)))
defer win.SelectObject(hdc, hFontOld)
var maxWidth int
if lb.model == nil {
return -1
}
count := lb.model.ItemCount()
for i := 0; i < count; i++ {
item := lb.itemString(i)
var s win.SIZE
str := syscall.StringToUTF16(item)
if !win.GetTextExtentPoint32(hdc, &str[0], int32(len(str)-1), &s) {
newError("GetTextExtentPoint32 failed")
return -1
}
maxWidth = maxi(maxWidth, int(s.CX))
}
return maxWidth
}
示例10: WriteStringReg
// Use to write string value to windows registry the HKEY in the next definition HHLM, HKCU, HKCC, HKCR, HKU
func WriteStringReg(hkey, path, name, val string) (err error) {
var handle syscall.Handle
switch hkey {
case "HKLM":
err = syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(""), 0, syscall.KEY_CREATE_SUB_KEY, &handle)
case "HKCC":
err = syscall.RegOpenKeyEx(syscall.HKEY_CURRENT_CONFIG, syscall.StringToUTF16Ptr(""), 0, syscall.KEY_CREATE_SUB_KEY, &handle)
case "HKCR":
err = syscall.RegOpenKeyEx(syscall.HKEY_CLASSES_ROOT, syscall.StringToUTF16Ptr(""), 0, syscall.KEY_CREATE_SUB_KEY, &handle)
case "HKCU":
err = syscall.RegOpenKeyEx(syscall.HKEY_CURRENT_USER, syscall.StringToUTF16Ptr(""), 0, syscall.KEY_CREATE_SUB_KEY, &handle)
case "HKU":
err = syscall.RegOpenKeyEx(syscall.HKEY_USERS, syscall.StringToUTF16Ptr(""), 0, syscall.KEY_CREATE_SUB_KEY, &handle)
default:
err = errors.New("Unknown HKEY: " + hkey)
return
}
if err != nil {
return
}
defer syscall.RegCloseKey(handle)
var d uint32
err = winapi.RegCreateKeyEx(handle, syscall.StringToUTF16Ptr(path), 0, nil, winapi.REG_OPTION_NON_VOLATILE, syscall.KEY_ALL_ACCESS, nil, &handle, &d)
if err != nil {
return
}
buf := syscall.StringToUTF16(val)
err = winapi.RegSetValueEx(handle, syscall.StringToUTF16Ptr(name), 0, syscall.REG_SZ, (*byte)(unsafe.Pointer(&buf[0])), uint32(len(buf)*2))
return
}
示例11: AddTrayIcon
func (w *Window) AddTrayIcon(ico Icon, tip string) {
if w.trayIconData != nil {
return
}
w.trayIconData = &w32.NOTIFYICONDATA{
/* Size */ uint32(unsafe.Sizeof(*w.trayIconData)),
/* Wnd */ w.handle,
/* ID */ 1,
/* Flags */ w32.NIF_MESSAGE | w32.NIF_ICON | w32.NIF_TIP | w32.NIF_SHOWTIP,
/* CallbackMessage */ WM_TRAYICON,
/* Icon */ w32.HICON(ico),
/* Tip */ [128]uint16{},
/* State */ 0,
/* StateMask */ 0,
/* Info */ [256]uint16{},
/* TimeoutOrVersion */ w32.NOTIFYICON_VERSION_4,
/* InfoTitle */ [64]uint16{},
/* InfoFlags */ 0,
/* Item */ w32.GUID{},
/* BalloonIcon */ 0,
}
tipbuf := syscall.StringToUTF16(tip)
copy(w.trayIconData.Tip[:], tipbuf)
w32.Shell_NotifyIcon(w32.NIM_ADD, w.trayIconData)
}
示例12: calculateMaxItemTextWidth
func (cb *ComboBox) calculateMaxItemTextWidth() int {
hdc := GetDC(cb.hWnd)
if hdc == 0 {
newError("GetDC failed")
return -1
}
defer ReleaseDC(cb.hWnd, hdc)
hFontOld := SelectObject(hdc, HGDIOBJ(cb.Font().handleForDPI(0)))
defer SelectObject(hdc, hFontOld)
var maxWidth int
count := cb.model.ItemCount()
for i := 0; i < count; i++ {
var s SIZE
str := syscall.StringToUTF16(cb.itemString(i))
if !GetTextExtentPoint32(hdc, &str[0], int32(len(str)-1), &s) {
newError("GetTextExtentPoint32 failed")
return -1
}
maxWidth = maxi(maxWidth, int(s.CX))
}
return maxWidth
}
示例13: genOFN
func genOFN(parent Controller, title, filter string, filterIndex uint, initialDir string, buf []uint16) *w32.OPENFILENAME {
var ofn w32.OPENFILENAME
ofn.StructSize = uint32(unsafe.Sizeof(ofn))
ofn.Owner = parent.Handle()
if filter != "" {
filterBuf := make([]uint16, len(filter)+1)
copy(filterBuf, syscall.StringToUTF16(filter))
// Replace '|' with the expcted '\0'
for i, c := range filterBuf {
if byte(c) == '|' {
filterBuf[i] = uint16(0)
}
}
ofn.Filter = &filterBuf[0]
ofn.FilterIndex = uint32(filterIndex)
}
ofn.File = &buf[0]
ofn.MaxFile = uint32(len(buf))
if initialDir != "" {
ofn.InitialDir = syscall.StringToUTF16Ptr(initialDir)
}
if title != "" {
ofn.Title = syscall.StringToUTF16Ptr(title)
}
ofn.Flags = w32.OFN_FILEMUSTEXIST
return &ofn
}
示例14: open
func open(path string, flag int, perm os.FileMode) (*os.File, error) {
if path == "" {
return nil, fmt.Errorf("cannot open empty filename")
}
var access uint32
switch flag {
case syscall.O_RDONLY:
access = syscall.GENERIC_READ
case syscall.O_WRONLY:
access = syscall.GENERIC_WRITE
case syscall.O_RDWR:
access = syscall.GENERIC_READ | syscall.GENERIC_WRITE
case syscall.O_WRONLY | syscall.O_CREAT:
access = syscall.GENERIC_ALL
default:
panic(fmt.Errorf("flag %v is not supported", flag))
}
fd, err := syscall.CreateFile(&(syscall.StringToUTF16(path)[0]),
access,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
nil,
syscall.OPEN_ALWAYS,
syscall.FILE_ATTRIBUTE_NORMAL,
0)
if err != nil {
return nil, err
}
return os.NewFile(uintptr(fd), path), nil
}
示例15: EditVariable
// if not existing, creating new one.
func EditVariable(etype EnvType, varName string, varValue string) error {
var rootkey HKEY
var subkey string
if etype == 0 {
rootkey = HKEY_CURRENT_USER
subkey = USR_SUBKEY
} else {
rootkey = HKEY_LOCAL_MACHINE
subkey = SYS_SUBKEY
}
var mykey HKEY
if ret := RegOpenKeyEx(rootkey, syscall.StringToUTF16Ptr(subkey), 0, KEY_WRITE, &mykey); ret != ERROR_SUCCESS {
return errors.New(fmt.Sprintf("EditVariable error, RegOpenKeyEx = %d", ret))
}
dataType := REG_SZ
if strings.Index(varValue, "%") != -1 {
dataType = REG_EXPAND_SZ
}
if ret := RegSetValueEx(mykey,
syscall.StringToUTF16Ptr(varName),
0,
uint64(dataType),
(*byte)(unsafe.Pointer(syscall.StringToUTF16Ptr(varValue))),
// In Bytes.
uint32(len(syscall.StringToUTF16(varValue))*2)); ret != ERROR_SUCCESS {
return errors.New(fmt.Sprintf("EditVariable error, RegSetValueEx = %d", ret))
}
return nil
}