当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.UTF16PtrFromString函数代码示例

本文整理汇总了Golang中syscall.UTF16PtrFromString函数的典型用法代码示例。如果您正苦于以下问题:Golang UTF16PtrFromString函数的具体用法?Golang UTF16PtrFromString怎么用?Golang UTF16PtrFromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了UTF16PtrFromString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: lookupFullName

func lookupFullName(domain, username, domainAndUser string) (string, error) {
	// try domain controller first
	name, e := syscall.TranslateAccountName(domainAndUser,
		syscall.NameSamCompatible, syscall.NameDisplay, 50)
	if e != nil {
		// domain lookup failed, perhaps this pc is not part of domain
		d, e := syscall.UTF16PtrFromString(domain)
		if e != nil {
			return "", e
		}
		u, e := syscall.UTF16PtrFromString(username)
		if e != nil {
			return "", e
		}
		var p *byte
		e = syscall.NetUserGetInfo(d, u, 10, &p)
		if e != nil {
			// path executed when a domain user is disconnected from the domain
			// pretend username is fullname
			return username, nil
		}
		defer syscall.NetApiBufferFree(p)
		i := (*syscall.UserInfo10)(unsafe.Pointer(p))
		if i.FullName == nil {
			return "", nil
		}
		name = syscall.UTF16ToString((*[1024]uint16)(unsafe.Pointer(i.FullName))[:])
	}
	return name, nil
}
开发者ID:mm120,项目名称:gcc,代码行数:30,代码来源:lookup_windows.go

示例2: initScreenWindow

func initScreenWindow() (err error) {
	swc, err := syscall.UTF16PtrFromString(screenWindowClass)
	if err != nil {
		return err
	}
	emptyString, err := syscall.UTF16PtrFromString("")
	if err != nil {
		return err
	}
	wc := _WNDCLASS{
		LpszClassName: swc,
		LpfnWndProc:   syscall.NewCallback(screenWindowWndProc),
		HIcon:         hDefaultIcon,
		HCursor:       hDefaultCursor,
		HInstance:     hThisInstance,
		HbrBackground: syscall.Handle(_COLOR_BTNFACE + 1),
	}
	_, err = _RegisterClass(&wc)
	if err != nil {
		return err
	}
	screenHWND, err = _CreateWindowEx(0,
		swc, emptyString,
		_WS_OVERLAPPEDWINDOW,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		_HWND_MESSAGE, 0, hThisInstance, 0)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:rdterner,项目名称:exp,代码行数:32,代码来源:screen.go

示例3: newWindow

func newWindow(opts *screen.NewWindowOptions) (syscall.Handle, error) {
	// TODO(brainman): convert windowClass to *uint16 once (in initWindowClass)
	wcname, err := syscall.UTF16PtrFromString(windowClass)
	if err != nil {
		return 0, err
	}
	title, err := syscall.UTF16PtrFromString("Shiny Window")
	if err != nil {
		return 0, err
	}
	w, h := _CW_USEDEFAULT, _CW_USEDEFAULT
	if opts != nil {
		if opts.Width > 0 {
			w = opts.Width
		}
		if opts.Height > 0 {
			h = opts.Height
		}
	}
	hwnd, err := _CreateWindowEx(0,
		wcname, title,
		_WS_OVERLAPPEDWINDOW,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		int32(w), int32(h),
		0, 0, hThisInstance, 0)
	if err != nil {
		return 0, err
	}
	// TODO(andlabs): use proper nCmdShow
	// TODO(andlabs): call UpdateWindow()

	return hwnd, nil
}
开发者ID:kardianos,项目名称:garage,代码行数:33,代码来源:win32.go

示例4: Subscribe

// Subscribe creates a new subscription to an event log channel.
func Subscribe(
	session EvtHandle,
	event windows.Handle,
	channelPath string,
	query string,
	bookmark EvtHandle,
	flags EvtSubscribeFlag,
) (EvtHandle, error) {
	var err error
	var cp *uint16
	if channelPath != "" {
		cp, err = syscall.UTF16PtrFromString(channelPath)
		if err != nil {
			return 0, err
		}
	}

	var q *uint16
	if query != "" {
		q, err = syscall.UTF16PtrFromString(query)
		if err != nil {
			return 0, err
		}
	}

	eventHandle, err := _EvtSubscribe(session, uintptr(event), cp, q, bookmark,
		0, 0, flags)
	if err != nil {
		return 0, err
	}

	return eventHandle, nil
}
开发者ID:MingchunZhao,项目名称:beats,代码行数:34,代码来源:wineventlog_windows.go

示例5: openfile

func openfile(flags uint32, b *FileBuilder) (d filedlg) {
	d.buf = make([]uint16, w32.MAX_PATH)
	d.opf = &w32.OPENFILENAME{
		File:    utf16ptr(d.buf),
		MaxFile: uint32(len(d.buf)),
		Flags:   flags,
	}
	d.opf.StructSize = uint32(unsafe.Sizeof(*d.opf))
	if b.StartDir != "" {
		d.opf.InitialDir, _ = syscall.UTF16PtrFromString(b.StartDir)
	}
	if b.Dlg.Title != "" {
		d.opf.Title, _ = syscall.UTF16PtrFromString(b.Dlg.Title)
	}
	for _, filt := range b.Filters {
		/* build utf16 string of form "Music File\0*.mp3;*.ogg;*.wav;\0" */
		d.filters = append(d.filters, utf16.Encode([]rune(filt.Desc))...)
		d.filters = append(d.filters, 0)
		for _, ext := range filt.Extensions {
			s := fmt.Sprintf("*.%s;", ext)
			d.filters = append(d.filters, utf16.Encode([]rune(s))...)
		}
		d.filters = append(d.filters, 0)
	}
	if d.filters != nil {
		d.filters = append(d.filters, 0, 0) // two extra NUL chars to terminate the list
		d.opf.Filter = utf16ptr(d.filters)
	}
	return d
}
开发者ID:sqweek,项目名称:dialog,代码行数:30,代码来源:dlgs_windows.go

示例6: ChangeUserPasswordLocalhost

// changeUserPasswordLocalhost changes the password for username on localhost
func (c *PasswordChanger) ChangeUserPasswordLocalhost(newPassword string) error {
	serverp, err := syscall.UTF16PtrFromString("localhost")
	if err != nil {
		return errors.Trace(err)
	}

	userp, err := syscall.UTF16PtrFromString("jujud")
	if err != nil {
		return errors.Trace(err)
	}

	passp, err := syscall.UTF16PtrFromString(newPassword)
	if err != nil {
		return errors.Trace(err)
	}

	info := netUserSetPassword{passp}

	err = netUserSetInfo(serverp, userp, changePasswordLevel, &info, nil)
	if err != nil {
		return errors.Trace(err)
	}

	return nil
}
开发者ID:imoapps,项目名称:juju,代码行数:26,代码来源:password_windows.go

示例7: savePNG

func savePNG(fileName string, newBMP winapi.HBITMAP) error {
	var gdiplusStartupInput winapi.GdiplusStartupInput
	var gdiplusToken winapi.GdiplusStartupOutput

	// GDI+ の初期化
	gdiplusStartupInput.GdiplusVersion = 1
	if winapi.GdiplusStartup(&gdiplusStartupInput, &gdiplusToken) != 0 {
		return fmt.Errorf("failed to initialize GDI+")
	}
	defer winapi.GdiplusShutdown()

	// HBITMAP から Bitmap を作成
	var bmp *winapi.GpBitmap
	if winapi.GdipCreateBitmapFromHBITMAP(newBMP, 0, &bmp) != 0 {
		return fmt.Errorf("failed to create HBITMAP")
	}
	defer winapi.GdipDisposeImage((*winapi.GpImage)(bmp))
	sclsid, err := syscall.UTF16PtrFromString("{557CF406-1A04-11D3-9A73-0000F81EF32E}")
	if err != nil {
		return err
	}
	clsid, err := CLSIDFromString(sclsid)
	if err != nil {
		return err
	}
	fname, err := syscall.UTF16PtrFromString(fileName)
	if err != nil {
		return err
	}
	if GdipSaveImageToFile(bmp, fname, clsid, nil) != 0 {
		return fmt.Errorf("failed to call PNG encoder")
	}
	return nil
}
开发者ID:mattn,项目名称:gyagowin,代码行数:34,代码来源:main.go

示例8: ReplaceFile

// ReplaceFile calls through to the Win32 ReplaceFile API, which can be found at the following
// URL: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365512(v=vs.85).aspx
func ReplaceFile(replaced string, replacement string, backup string, flags Flag) error {
	_, err := os.Stat(replaced)
	if err != nil {
		if os.IsNotExist(err) {
			f, err := os.Create(replaced)
			if err != nil {
				return err
			}
			f.Close()
		}
	}
	replacedPtr, err := syscall.UTF16PtrFromString(replaced)
	if err != nil {
		return err
	}

	replacementPtr, err := syscall.UTF16PtrFromString(replacement)
	if err != nil {
		return err
	}

	backupPtr, err := syscall.UTF16PtrFromString(backup)
	if err != nil {
		return err
	}

	return replaceFileW(replacedPtr, replacementPtr, backupPtr, uint32(flags))
}
开发者ID:Tweenagedream,项目名称:grumble,代码行数:30,代码来源:replacefile_windows.go

示例9: ShellExecute

// Call ShellExecute-API: edit,explore,open and so on.
func ShellExecute(action string, path string, param string, directory string) error {
	actionP, actionErr := syscall.UTF16PtrFromString(action)
	if actionErr != nil {
		return actionErr
	}
	pathP, pathErr := syscall.UTF16PtrFromString(path)
	if pathErr != nil {
		return pathErr
	}
	paramP, paramErr := syscall.UTF16PtrFromString(param)
	if paramErr != nil {
		return paramErr
	}
	directoryP, directoryErr := syscall.UTF16PtrFromString(directory)
	if directoryErr != nil {
		return directoryErr
	}
	status, _, _ := shellExecute.Call(
		uintptr(0),
		uintptr(unsafe.Pointer(actionP)),
		uintptr(unsafe.Pointer(pathP)),
		uintptr(unsafe.Pointer(paramP)),
		uintptr(unsafe.Pointer(directoryP)),
		SW_SHOWNORMAL)

	if status <= 32 {
		if err := syscall.GetLastError(); err != nil {
			return err
		} else {
			return fmt.Errorf("Error(%d) in ShellExecuteW()", status)
		}
	}
	return nil
}
开发者ID:tyochiai,项目名称:nyagos,代码行数:35,代码来源:shellexecute.go

示例10: MyRegisterClass

func MyRegisterClass(hInstance winapi.HINSTANCE) winapi.ATOM {
	var wc winapi.WNDCLASSEX

	wc.CbSize = uint32(unsafe.Sizeof(winapi.WNDCLASSEX{}))
	wc.Style = 0
	wc.LpfnWndProc = syscall.NewCallback(WndProc)
	wc.CbClsExtra = 0
	wc.CbWndExtra = 0
	wc.HInstance = hInstance
	wc.HIcon = winapi.LoadIcon(hInstance, winapi.MAKEINTRESOURCE(132))
	wc.HCursor = winapi.LoadCursor(0, winapi.MAKEINTRESOURCE(winapi.IDC_CROSS))
	wc.HbrBackground = 0
	wc.LpszMenuName = nil
	wc.LpszClassName, _ = syscall.UTF16PtrFromString("GYAZOWIN")

	winapi.RegisterClassEx(&wc)

	var lwc winapi.WNDCLASSEX
	lwc.CbSize = uint32(unsafe.Sizeof(winapi.WNDCLASSEX{}))
	lwc.Style = winapi.CS_HREDRAW | winapi.CS_VREDRAW
	lwc.LpfnWndProc = syscall.NewCallback(LayerWndProc)
	lwc.CbClsExtra = 0
	lwc.CbWndExtra = 0
	lwc.HInstance = hInstance
	lwc.HIcon = winapi.LoadIcon(hInstance, winapi.MAKEINTRESOURCE(132))
	lwc.HCursor = winapi.LoadCursor(0, winapi.MAKEINTRESOURCE(winapi.IDC_CROSS))
	lwc.HbrBackground = winapi.HBRUSH(winapi.GetStockObject(winapi.WHITE_BRUSH))
	lwc.LpszMenuName = nil
	lwc.LpszClassName, _ = syscall.UTF16PtrFromString("GYAZOWINL")

	return winapi.RegisterClassEx(&lwc)
}
开发者ID:mattn,项目名称:gyagowin,代码行数:32,代码来源:main.go

示例11: addOrUpdateMenuItem

func addOrUpdateMenuItem(item *MenuItem) {
	var disabled C.short = 0
	if item.disabled {
		disabled = 1
	}
	var checked C.short = 0
	if item.checked {
		checked = 1
	}

	title, err := syscall.UTF16PtrFromString(item.title)
	if err != nil {
		panic(err)
	}

	tooltip, err := syscall.UTF16PtrFromString(item.tooltip)
	if err != nil {
		panic(err)
	}

	C.add_or_update_menu_item(
		C.int(item.id),
		(*C.wchar_t)(unsafe.Pointer(title)),
		(*C.wchar_t)(unsafe.Pointer(tooltip)),
		disabled,
		checked,
	)
}
开发者ID:thomasf,项目名称:alkasir,代码行数:28,代码来源:cgo_windows.go

示例12: savePNG

func savePNG(fileName string, newBMP []byte) error {
	var gdiplusStartupInput winapi.GdiplusStartupInput
	var gdiplusToken winapi.GdiplusStartupOutput

	gdiplusStartupInput.GdiplusVersion = 1
	if winapi.GdiplusStartup(&gdiplusStartupInput, &gdiplusToken) != 0 {
		return fmt.Errorf("failed to initialize GDI+")
	}
	defer winapi.GdiplusShutdown()

	var bmp *winapi.GpBitmap
	if r0, _, _ := procGdipCreateBitmapFromGdiDib.Call(
		uintptr(unsafe.Pointer(&newBMP[0])),
		uintptr(unsafe.Pointer(&newBMP[52])),
		uintptr(unsafe.Pointer(&bmp))); r0 != 0 {
		return fmt.Errorf("failed to create bitmap")
	}
	defer winapi.GdipDisposeImage((*winapi.GpImage)(bmp))
	sclsid, err := syscall.UTF16PtrFromString("{557CF406-1A04-11D3-9A73-0000F81EF32E}")
	if err != nil {
		return err
	}
	clsid, err := CLSIDFromString(sclsid)
	if err != nil {
		return err
	}
	fname, err := syscall.UTF16PtrFromString(fileName)
	if err != nil {
		return err
	}
	if GdipSaveImageToFile(bmp, fname, clsid, nil) != 0 {
		return fmt.Errorf("failed to call PNG encoder")
	}
	return nil
}
开发者ID:chai2010-playground,项目名称:pastepng,代码行数:35,代码来源:main.go

示例13: Open

func (el *eventLog) Open(recordNumber uint32) error {
	// If uncServerPath is nil the local computer is used.
	var uncServerPath *uint16
	var err error
	if el.uncServerPath != "" {
		uncServerPath, err = syscall.UTF16PtrFromString(el.uncServerPath)
		if err != nil {
			return err
		}
	}

	providerName, err := syscall.UTF16PtrFromString(el.name)
	if err != nil {
		return err
	}

	handle, err := openEventLog(uncServerPath, providerName)
	if err != nil {
		return err
	}

	el.handle = handle
	el.recordNumber = recordNumber
	el.readBuf = make([]byte, maxEventBufferSize)
	// TODO: Start with this buffer smaller and grow it when needed.
	el.formatBuf = make([]byte, maxFormatMessageBufferSize)
	return nil
}
开发者ID:ruflin,项目名称:winlogbeat,代码行数:28,代码来源:eventlog_windows.go

示例14: Open

func (el *eventLog) Open(recordNumber uint32) error {
	// If uncServerPath is nil the local computer is used.
	var uncServerPath *uint16
	var err error
	if el.uncServerPath != "" {
		uncServerPath, err = syscall.UTF16PtrFromString(el.uncServerPath)
		if err != nil {
			return err
		}
	}

	providerName, err := syscall.UTF16PtrFromString(el.name)
	if err != nil {
		return err
	}

	detailf("%s Open(recordNumber=%d) calling openEventLog(uncServerPath=%s, providerName=%s)",
		el.logPrefix, recordNumber, el.uncServerPath, el.name)
	handle, err := openEventLog(uncServerPath, providerName)
	if err != nil {
		return err
	}

	numRecords, err := getNumberOfEventLogRecords(handle)
	if err != nil {
		return err
	}

	var oldestRecord, newestRecord uint32
	if numRecords > 0 {
		el.recordNumber = recordNumber
		el.ignoreFirst = true

		oldestRecord, err = getOldestEventLogRecord(handle)
		if err != nil {
			return err
		}
		newestRecord = oldestRecord + numRecords - 1

		if recordNumber < oldestRecord || recordNumber > newestRecord {
			el.recordNumber = oldestRecord
			el.ignoreFirst = false
		}
	} else {
		el.recordNumber = 0
		el.seek = false
		el.ignoreFirst = false
	}

	logp.Info("%s contains %d records. Record number range [%d, %d]. Starting "+
		"at %d (ignoringFirst=%t)", el.logPrefix, numRecords, oldestRecord,
		newestRecord, el.recordNumber, el.ignoreFirst)

	el.seek = true
	el.handle = handle
	el.readBuf = make([]byte, maxEventBufferSize)
	// TODO: Start with this buffer smaller and grow it when needed.
	el.formatBuf = make([]byte, maxFormatMessageBufferSize)
	return nil
}
开发者ID:bqk-,项目名称:packetbeat,代码行数:60,代码来源:eventlog_windows.go

示例15: Rename

func Rename(src, dst string) error {
	kernel32, err := syscall.LoadLibrary("kernel32.dll")
	if err != nil {
		return err
	}
	defer syscall.FreeLibrary(kernel32)
	moveFileExUnicode, err := syscall.GetProcAddress(kernel32, "MoveFileExW")
	if err != nil {
		return err
	}

	srcString, err := syscall.UTF16PtrFromString(src)
	if err != nil {
		return err
	}

	dstString, err := syscall.UTF16PtrFromString(dst)
	if err != nil {
		return err
	}

	srcPtr := uintptr(unsafe.Pointer(srcString))
	dstPtr := uintptr(unsafe.Pointer(dstString))

	MOVEFILE_REPLACE_EXISTING := 0x1
	flag := uintptr(MOVEFILE_REPLACE_EXISTING)

	_, _, callErr := syscall.Syscall(uintptr(moveFileExUnicode), 3, srcPtr, dstPtr, flag)
	if callErr != 0 {
		return callErr
	}

	return nil
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:34,代码来源:rename_windows.go


注:本文中的syscall.UTF16PtrFromString函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。