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


Golang syscall.StringToUTF16Ptr函数代码示例

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


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

示例1: GetValueBinary

func (self *RegKey) GetValueBinary(valueName string) ([]byte, error) {
	var valueType uint32
	var size uint32
	err := wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&valueType,
		nil,
		&size)
	if err != nil {
		return nil, NewWindowsError("RegQueryValueEx", err)
	}
	if valueType != wrappers.REG_BINARY {
		// use the same error code as RegGetValue, although that function is not used here in order to maintain
		// compatibility with older versions of Windows
		return nil, NewWindowsError("RegQueryValueEx", wrappers.ERROR_UNSUPPORTED_TYPE)
	}
	value := make([]byte, size)
	err = wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		&value[0],
		&size)
	if err != nil {
		return nil, NewWindowsError("RegQueryValueEx", err)
	}
	return value, nil
}
开发者ID:winlabs,项目名称:gowin32,代码行数:31,代码来源:registry.go

示例2: RegGetString

func RegGetString(hKey HKEY, subKey string, value string) string {
	var bufLen uint32
	procRegGetValue.Call(
		uintptr(hKey),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))),
		uintptr(RRF_RT_REG_SZ),
		0,
		0,
		uintptr(unsafe.Pointer(&bufLen)))

	if bufLen == 0 {
		return ""
	}

	buf := make([]uint16, bufLen)
	ret, _, _ := procRegGetValue.Call(
		uintptr(hKey),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(subKey))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(value))),
		uintptr(RRF_RT_REG_SZ),
		0,
		uintptr(unsafe.Pointer(&buf[0])),
		uintptr(unsafe.Pointer(&bufLen)))

	if ret != ERROR_SUCCESS {
		return ""
	}

	return syscall.UTF16ToString(buf)
}
开发者ID:RunningSnail,项目名称:w32,代码行数:31,代码来源:advapi32.go

示例3: onInsertingListViewItem

func (lv *ListView) onInsertingListViewItem(index int, item *ListViewItem) (err os.Error) {
	var lvi LVITEM

	lvi.Mask = LVIF_TEXT
	lvi.IItem = index

	texts := item.Texts()
	if len(texts) > 0 {
		lvi.PszText = syscall.StringToUTF16Ptr(texts[0])
	}

	i := SendMessage(lv.hWnd, LVM_INSERTITEM, 0, uintptr(unsafe.Pointer(&lvi)))
	if int(i) == -1 {
		return newError("ListView.onInsertingListViewItem: Failed to insert item.")
	}

	colCount := lv.columns.Len()

	for colIndex := 1; colIndex < colCount; colIndex++ {
		lvi.ISubItem = colIndex

		if colIndex < len(texts) {
			lvi.PszText = syscall.StringToUTF16Ptr(texts[colIndex])
		} else {
			lvi.PszText = nil
		}

		ret := SendMessage(lv.hWnd, LVM_SETITEM, 0, uintptr(unsafe.Pointer(&lvi)))
		if ret == 0 {
			return newError("ListView.onInsertingListViewItem: Failed to set sub item.")
		}
	}

	return
}
开发者ID:lalitjsraks,项目名称:walk,代码行数:35,代码来源:listview.go

示例4: RegistryKeyUint32

func RegistryKeyUint32(rootKey *RegistryKey, subKeyPath, valueName string) (value uint32, err error) {
	var hKey win.HKEY
	if win.RegOpenKeyEx(
		rootKey.hKey,
		syscall.StringToUTF16Ptr(subKeyPath),
		0,
		win.KEY_READ,
		&hKey) != win.ERROR_SUCCESS {

		return 0, newError("RegistryKeyUint32: Failed to open subkey.")
	}
	defer win.RegCloseKey(hKey)

	bufSize := uint32(4)

	if win.ERROR_SUCCESS != win.RegQueryValueEx(
		hKey,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		(*byte)(unsafe.Pointer(&value)),
		&bufSize) {

		return 0, newError("RegQueryValueEx")
	}

	return
}
开发者ID:kumakichi,项目名称:walk,代码行数:28,代码来源:registry.go

示例5: GetOperatingSystem

func GetOperatingSystem() (string, error) {

	var h syscall.Handle

	// Default return value
	ret := "Unknown Operating System"

	if err := syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE,
		syscall.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`),
		0,
		syscall.KEY_READ,
		&h); err != nil {
		return ret, err
	}
	defer syscall.RegCloseKey(h)

	var buf [1 << 10]uint16
	var typ uint32
	n := uint32(len(buf) * 2) // api expects array of bytes, not uint16

	if err := syscall.RegQueryValueEx(h,
		syscall.StringToUTF16Ptr("ProductName"),
		nil,
		&typ,
		(*byte)(unsafe.Pointer(&buf[0])),
		&n); err != nil {
		return ret, err
	}
	ret = syscall.UTF16ToString(buf[:])

	return ret, nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:32,代码来源:operatingsystem_windows.go

示例6: IsServiceRunning

func IsServiceRunning(serviceName string) (bool, error) {
	// This function requires fewer access rights than using the above classes and can be used to check if a service
	// is running without administrator access.
	scmhandle, err := wrappers.OpenSCManager(
		nil,
		syscall.StringToUTF16Ptr(wrappers.SERVICES_ACTIVE_DATABASE),
		wrappers.SC_MANAGER_CONNECT)
	if err != nil {
		return false, NewWindowsError("OpenSCManager", err)
	}
	defer wrappers.CloseServiceHandle(scmhandle)
	handle, err := wrappers.OpenService(
		scmhandle,
		syscall.StringToUTF16Ptr(serviceName),
		wrappers.SERVICE_QUERY_STATUS)
	if err == wrappers.ERROR_SERVICE_DOES_NOT_EXIST {
		return false, nil
	} else if err != nil {
		return false, NewWindowsError("OpenService", err)
	}
	defer wrappers.CloseServiceHandle(handle)
	var status wrappers.SERVICE_STATUS
	if err := wrappers.QueryServiceStatus(handle, &status); err != nil {
		return false, NewWindowsError("QueryServiceStatus", err)
	}
	return status.CurrentState == wrappers.SERVICE_RUNNING, nil
}
开发者ID:winlabs,项目名称:gowin32,代码行数:27,代码来源:service.go

示例7: OpenHTTPRequest

func (self *InternetConnection) OpenHTTPRequest(verb string, objectName string, version string, referer string, acceptTypes []string, flags HTTPRequestFlags) (*HTTPRequest, error) {
	var versionRaw *uint16
	if version != "" {
		versionRaw = syscall.StringToUTF16Ptr(version)
	}
	var refererRaw *uint16
	if referer != "" {
		refererRaw = syscall.StringToUTF16Ptr(referer)
	}
	var acceptTypesRaw **uint16
	if acceptTypes != nil {
		acceptTypesPtrs := make([]*uint16, len(acceptTypes), len(acceptTypes)+1)
		for i := range acceptTypes {
			acceptTypesPtrs[i] = syscall.StringToUTF16Ptr(acceptTypes[i])
		}
		acceptTypesPtrs = append(acceptTypesPtrs, nil)
		acceptTypesRaw = &acceptTypesPtrs[0]
	}
	handle, err := wrappers.HttpOpenRequest(
		self.handle,
		syscall.StringToUTF16Ptr(verb),
		syscall.StringToUTF16Ptr(objectName),
		versionRaw,
		refererRaw,
		acceptTypesRaw,
		uint32(flags),
		0)
	if err != nil {
		return nil, NewWindowsError("HttpOpenRequest", err)
	}
	return &HTTPRequest{InternetFile{InternetObject{handle: handle}}}, nil
}
开发者ID:winlabs,项目名称:gowin32,代码行数:32,代码来源:internet.go

示例8: getPath

func getPath() {
	var root syscall.Handle

	error := syscall.RegOpenKeyEx(syscall.HKEY_CURRENT_USER, syscall.StringToUTF16Ptr(`Environment`),
		0, syscall.KEY_READ, &root)

	defer syscall.RegCloseKey(root)

	var buf [1 << 10]uint16

	var typ uint32
	n := uint32(len(buf)) // api expects array of bytes, not uint16
	if syscall.RegQueryValueEx(
		root, syscall.StringToUTF16Ptr(`Path`),
		nil, &typ, (*byte)(unsafe.Pointer(&buf[0])), &n) != nil {

	}

	path := syscall.UTF16ToString(buf[:])

	fmt.Println(path)

	if error != nil {
		fmt.Println(error)
		return
	}

}
开发者ID:ludovicdeluna,项目名称:go,代码行数:28,代码来源:query.go

示例9: GetLocalAccountByName

func GetLocalAccountByName(accountName string) (SecurityID, string, SecurityIDType, error) {
	var neededForSid uint32
	var neededForDomain uint32
	var use int32
	wrappers.LookupAccountName(
		nil,
		syscall.StringToUTF16Ptr(accountName),
		nil,
		&neededForSid,
		nil,
		&neededForDomain,
		&use)
	sidBuf := make([]byte, neededForSid)
	sid := (*wrappers.SID)(unsafe.Pointer(&sidBuf[0]))
	domainBuf := make([]uint16, neededForDomain)
	err := wrappers.LookupAccountName(
		nil,
		syscall.StringToUTF16Ptr(accountName),
		sid,
		&neededForSid,
		&domainBuf[0],
		&neededForDomain,
		&use)
	if err != nil {
		return SecurityID{}, "", 0, NewWindowsError("LookupAccountName", err)
	}
	return SecurityID{sid}, syscall.UTF16ToString(domainBuf), SecurityIDType(use), nil
}
开发者ID:winlabs,项目名称:gowin32,代码行数:28,代码来源:security.go

示例10: 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
}
开发者ID:ZhuBicen,项目名称:EnvSetting,代码行数:35,代码来源:reg.go

示例11: main

func main() {
	getPath()
	return

	var root syscall.Handle

	error := syscall.RegOpenKeyEx(syscall.HKEY_CURRENT_USER, syscall.StringToUTF16Ptr(`Control Panel\Accessibility\HighContrast`),
		0, syscall.KEY_READ, &root)

	defer syscall.RegCloseKey(root)

	var buf [1 << 10]uint16

	var typ uint32
	n := uint32(len(buf)) // api expects array of bytes, not uint16
	if syscall.RegQueryValueEx(
		root, syscall.StringToUTF16Ptr(`Previous High Contrast Scheme MUI Value`),
		nil, &typ, (*byte)(unsafe.Pointer(&buf[0])), &n) != nil {

	}

	path := syscall.UTF16ToString(buf[:])

	fmt.Println(path)

	if error != nil {
		fmt.Println(error)
		return
	}

}
开发者ID:ludovicdeluna,项目名称:go,代码行数:31,代码来源:query.go

示例12: LoadVariables

func LoadVariables(etype EnvType) (map[string]string, error) {
	var hkey HKEY
	envMap := make(map[string]string)
	if etype == 0 {
		RegOpenKeyEx(HKEY_CURRENT_USER, syscall.StringToUTF16Ptr(`Environment`), 0, KEY_READ, &hkey)
	} else {
		RegOpenKeyEx(HKEY_LOCAL_MACHINE,
			syscall.StringToUTF16Ptr(`SYSTEM\CurrentControlSet\Control\Session Manager\Environment`),
			0, KEY_READ, &hkey)
	}

	for i := 0; ; i++ {

		var valueLen uint32 = 256
		valueBuffer := make([]uint16, 256)

		var dataLen uint32 = 0
		var dataType uint32 = 0

		if ERROR_NO_MORE_ITEMS == RegEnumValue(hkey, uint32(i), &valueBuffer[0], &valueLen, nil, &dataType, nil, &dataLen) {
			break
		}

		dataBuffer := make([]uint16, dataLen/2+2)

		if ERROR_SUCCESS != RegQueryValueEx(hkey, &valueBuffer[0], nil, &dataType, (*byte)(unsafe.Pointer(&dataBuffer[0])), &dataLen) {
			return nil, errors.New("ERROR2")
		}
		envMap[syscall.UTF16ToString(valueBuffer)] = syscall.UTF16ToString(dataBuffer)
		if syscall.UTF16ToString(valueBuffer) == "Path" {
			log.Println("Path = ", syscall.UTF16ToString(dataBuffer))
		}
	}
	return envMap, nil
}
开发者ID:ZhuBicen,项目名称:EnvSetting,代码行数:35,代码来源:reg.go

示例13: GetValueString

func (self *RegKey) GetValueString(valueName string) (string, error) {
	var valueType uint32
	var size uint32
	err := wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&valueType,
		nil,
		&size)
	if err != nil {
		return "", NewWindowsError("RegQueryValueEx", err)
	}
	if valueType != wrappers.REG_SZ {
		// use the same error code as RegGetValue, although that function is not used here in order to maintain
		// compatibility with older versions of Windows
		return "", NewWindowsError("RegQueryValueEx", wrappers.ERROR_UNSUPPORTED_TYPE)
	}
	buf := make([]uint16, size/2)
	err = wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		(*byte)(unsafe.Pointer(&buf[0])),
		&size)
	if err != nil {
		return "", NewWindowsError("RegQueryValueEx", err)
	}
	return syscall.UTF16ToString(buf), nil
}
开发者ID:winlabs,项目名称:gowin32,代码行数:31,代码来源:registry.go

示例14: GetValueQWORD

func (self *RegKey) GetValueQWORD(valueName string) (uint64, error) {
	var valueType uint32
	var size uint32
	err := wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		&valueType,
		nil,
		&size)
	if err != nil {
		return 0, NewWindowsError("RegQueryValueEx", err)
	}
	if valueType != wrappers.REG_QWORD {
		// use the same error code as RegGetValue, although that function is not used here in order to maintain
		// compatibility with older versions of Windows
		return 0, NewWindowsError("RegQueryValueEx", wrappers.ERROR_UNSUPPORTED_TYPE)
	}
	var value uint64
	err = wrappers.RegQueryValueEx(
		self.handle,
		syscall.StringToUTF16Ptr(valueName),
		nil,
		nil,
		(*byte)(unsafe.Pointer(&value)),
		&size)
	if err != nil {
		return 0, NewWindowsError("RegQueryValueEx", err)
	}
	return value, nil
}
开发者ID:winlabs,项目名称:gowin32,代码行数:31,代码来源:registry.go

示例15: OpenEventLog

func OpenEventLog(servername string, sourcename string) HANDLE {
	ret, _, _ := procOpenEventLog.Call(
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(servername))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(sourcename))))

	return HANDLE(ret)
}
开发者ID:PagerDuty,项目名称:nomad,代码行数:7,代码来源:advapi32.go


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