本文整理汇总了Golang中syscall.UTF16ToString函数的典型用法代码示例。如果您正苦于以下问题:Golang UTF16ToString函数的具体用法?Golang UTF16ToString怎么用?Golang UTF16ToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UTF16ToString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetPrinterPort
func GetPrinterPort(printerName string) (string, error) {
printerPort := "LPT1"
const flags = PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS
var needed, returned uint32
buf := make([]byte, 1)
err := EnumPrinters(flags, nil, 5, &buf[0], uint32(len(buf)), &needed, &returned)
if err != nil {
if err != syscall.ERROR_INSUFFICIENT_BUFFER {
return "", err
}
buf = make([]byte, needed)
err = EnumPrinters(flags, nil, 5, &buf[0], uint32(len(buf)), &needed, &returned)
if err != nil {
return "", err
}
}
ps := (*[1024]PRINTER_INFO_5)(unsafe.Pointer(&buf[0]))[:returned]
for _, p := range ps {
v := (*[1024]uint16)(unsafe.Pointer(p.PrinterName))[:]
if strings.Compare(syscall.UTF16ToString(v), printerName) == 0 {
v := (*[1024]uint16)(unsafe.Pointer(p.PortName))[:]
printerPort = strings.Split(syscall.UTF16ToString(v), ",")[0]
}
}
return printerPort, nil
}
示例2: getFromSnapProcess
func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
snap := w32.CreateToolhelp32Snapshot(w32.TH32CS_SNAPPROCESS, uint32(pid))
if snap == 0 {
return 0, 0, "", syscall.GetLastError()
}
defer w32.CloseHandle(snap)
var pe32 w32.PROCESSENTRY32
pe32.DwSize = uint32(unsafe.Sizeof(pe32))
if w32.Process32First(snap, &pe32) == false {
return 0, 0, "", syscall.GetLastError()
}
if pe32.Th32ProcessID == uint32(pid) {
szexe := syscall.UTF16ToString(pe32.SzExeFile[:])
return int32(pe32.Th32ParentProcessID), int32(pe32.CntThreads), szexe, nil
}
for w32.Process32Next(snap, &pe32) {
if pe32.Th32ProcessID == uint32(pid) {
szexe := syscall.UTF16ToString(pe32.SzExeFile[:])
return int32(pe32.Th32ParentProcessID), int32(pe32.CntThreads), szexe, nil
}
}
return 0, 0, "", errors.New("Couldn't find pid:" + string(pid))
}
示例3: OpenProcess
func OpenProcess(pid uint32) (*Process, error) {
const da = syscall.STANDARD_RIGHTS_READ | syscall.PROCESS_QUERY_INFORMATION | syscall.SYNCHRONIZE
h, err := syscall.OpenProcess(da, false, uint32(pid))
if err != nil {
return nil, os.NewSyscallError("OpenProcess", err)
}
procEntry, err := win32.FindProcessEntry(pid)
if err != nil {
return nil, err
}
modEntry, err := win32.FirstModuleEntry(pid)
if err != nil {
return nil, err
}
handleCount, err := win32.GetProcessHandleCount(h)
if err != nil {
return nil, err
}
return &Process{
Pid: pid,
handle: uintptr(h),
ParentId: procEntry.ParentProcessID,
Name: syscall.UTF16ToString(modEntry.ModuleName[:]),
Executable: syscall.UTF16ToString(procEntry.ExeFile[:]),
CmdLine: syscall.UTF16ToString(modEntry.ExePath[:]),
HandleCount: handleCount,
ThreadCount: procEntry.Threads,
}, nil
}
示例4: GetDynLibDirs
// Search Path Used by Windows to Locate a DLL - https://msdn.microsoft.com/en-us/library/7d83bc18.aspx
func GetDynLibDirs() (dirs []string, err error) {
// The directory where the executable module for the current process is located.
path, err := osx.Executable()
if err != nil {
return
}
dirs = append(dirs, path)
// The current directory.
path, err = os.Getwd()
if err != nil {
return
}
dirs = append(dirs, path)
// The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
buf := make([]uint16, syscall.MAX_PATH)
_, err = syscallx.GetSystemDirectory(&buf[0], syscall.MAX_PATH)
if err != nil {
return
}
path = syscall.UTF16ToString(buf)
dirs = append(dirs, path)
// The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
_, err = syscallx.GetWindowsDirectory(&buf[0], syscall.MAX_PATH)
if err != nil {
return
}
path = syscall.UTF16ToString(buf)
dirs = append(dirs, path)
// The directories listed in the PATH environment variable.
path = os.Getenv("PATH")
dirs = append(dirs, strings.Split(path, string(os.PathListSeparator))...)
return
}
示例5: GetVolumeInfo
func GetVolumeInfo(rootPathName string) (*VolumeInfo, error) {
var volumeSerialNumber uint32
var maximumComponentLength uint32
var fileSystemFlags uint32
volumeNameBuffer := make([]uint16, syscall.MAX_PATH+1)
fileSystemNameBuffer := make([]uint16, syscall.MAX_PATH+1)
err := wrappers.GetVolumeInformation(
syscall.StringToUTF16Ptr(rootPathName),
&volumeNameBuffer[0],
syscall.MAX_PATH+1,
&volumeSerialNumber,
&maximumComponentLength,
&fileSystemFlags,
&fileSystemNameBuffer[0],
syscall.MAX_PATH+1)
if err != nil {
return nil, NewWindowsError("GetVolumeInformation", err)
}
return &VolumeInfo{
VolumeName: syscall.UTF16ToString(volumeNameBuffer),
VolumeSerialNumber: uint(volumeSerialNumber),
MaximumComponentLength: uint(maximumComponentLength),
FileSystemFlags: FileSystemFlags(fileSystemFlags),
FileSystemName: syscall.UTF16ToString(fileSystemNameBuffer),
}, nil
}
示例6: getAllWindowsLocaleFrom
func getAllWindowsLocaleFrom(sysCall string) (string, error) {
dll, err := syscall.LoadDLL("kernel32")
if err != nil {
return "", errors.New("Could not find kernel32 dll")
}
proc, err := dll.FindProc(sysCall)
if err != nil {
return "", err
}
locale, _, dllError := proc.Call()
if locale == 0 {
return "", errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
}
proc, err = dll.FindProc("GetLocaleInfoW")
if err != nil {
return "", err
}
langBuf := make([]uint16, LOCALE_SISO_NAME_MAX_LENGTH)
r, _, dllError := proc.Call(locale, uintptr(LOCALE_SISO639LANGNAME), uintptr(unsafe.Pointer(&langBuf[0])), uintptr(LOCALE_SISO_NAME_MAX_LENGTH))
if r == 0 {
err = errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
return "", err
}
countryBuf := make([]uint16, LOCALE_SISO_NAME_MAX_LENGTH)
r, _, dllError = proc.Call(locale, uintptr(LOCALE_SISO3166CTRYNAME), uintptr(unsafe.Pointer(&countryBuf[0])), uintptr(LOCALE_SISO_NAME_MAX_LENGTH))
if r == 0 {
err = errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
return "", err
}
return syscall.UTF16ToString(langBuf) + "-" + syscall.UTF16ToString(countryBuf), nil
}
示例7: GetModuleBase
// GetModuleBase takes a module name as an argument. (e.g. "kernel32.dll")
// Returns the modules base address.
//
// (Mostly taken from genkman's gist: https://gist.github.com/henkman/3083408)
// TODO(Andoryuuta): Figure out possible licencing issues with this, or rewrite.
func (p *Process) GetModuleBase(moduleName string) (uintptr, error) {
snap, ok := w32.CreateToolhelp32Snapshot(w32.TH32CS_SNAPMODULE32|w32.TH32CS_SNAPALL|w32.TH32CS_SNAPMODULE, uint32(p.PID))
if !ok {
return 0, errors.New("Error trying on create toolhelp32 snapshot.")
}
defer w32.CloseHandle(snap)
var me32 w32.MODULEENTRY32
me32.DwSize = uint32(unsafe.Sizeof(me32))
// Get first module
if !w32.Module32First(snap, &me32) {
return 0, errors.New("Error trying to get first module.")
}
// Check first module
if syscall.UTF16ToString(me32.SzModule[:]) == moduleName {
return uintptr(unsafe.Pointer(me32.ModBaseAddr)), nil
}
// Loop all modules remaining
for w32.Module32Next(snap, &me32) {
// Check this module
if syscall.UTF16ToString(me32.SzModule[:]) == moduleName {
return uintptr(unsafe.Pointer(me32.ModBaseAddr)), nil
}
}
// If this is reached, then we couldn't find the module
return 0, errors.New("Couldn't Find Module.")
}
示例8: 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
}
示例9: GetProcessModules
func GetProcessModules(pid uint32) ([]ModuleInfo, error) {
hSnapshot, err := wrappers.CreateToolhelp32Snapshot(wrappers.TH32CS_SNAPMODULE, pid)
if err != nil {
return nil, NewWindowsError("CreateToolhelp32Snapshot", err)
}
defer wrappers.CloseHandle(hSnapshot)
me := wrappers.MODULEENTRY32{}
me.Size = uint32(unsafe.Sizeof(me))
if err := wrappers.Module32First(hSnapshot, &me); err != nil {
return nil, NewWindowsError("Module32First", err)
}
mi := []ModuleInfo{}
for {
mi = append(mi, ModuleInfo{
ProcessID: uint(me.ProcessID),
ModuleBaseAddress: me.ModBaseAddr,
ModuleBaseSize: uint(me.ModBaseSize),
ModuleHandle: me.Module,
ModuleName: syscall.UTF16ToString((&me.ModuleName)[:]),
ExePath: syscall.UTF16ToString((&me.ExePath)[:]),
})
err := wrappers.Module32Next(hSnapshot, &me)
if err == wrappers.ERROR_NO_MORE_FILES {
return mi, nil
} else if err != nil {
return nil, NewWindowsError("Module32Next", err)
}
}
}
示例10: Current
func (self *FindFile) Current() FindFileItem {
return FindFileItem{
FileAttributes: FileAttributes(self.current.FileAttributes),
FileSize: (uint64(self.current.FileSizeHigh) << 32) | uint64(self.current.FileSizeLow),
ReparseTag: ReparseTag(self.current.Reserved0),
FileName: syscall.UTF16ToString(self.current.FileName[:]),
AlternateFileName: syscall.UTF16ToString(self.current.AlternateFileName[:]),
}
}
示例11: abbrev
// abbrev returns the abbreviations to use for the given zone z.
func abbrev(z *syscall.Timezoneinformation) (std, dst string) {
stdName := syscall.UTF16ToString(z.StandardName[:])
a, ok := abbrs[stdName]
if !ok {
// fallback to using capital letters
dstName := syscall.UTF16ToString(z.DaylightName[:])
return extractCAPS(stdName), extractCAPS(dstName)
}
return a.std, a.dst
}
示例12: RegQuery
func RegQuery(regname, installer_name, args string) (result string) {
var handle, subtestkey syscall.Handle
var csubkey uint32
var list [1 << 10]string
if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(regname), 0, syscall.KEY_READ, &handle) != nil {
return
}
defer syscall.RegCloseKey(handle)
csubkey = QueryKey(handle, &list)
// fmt.Println("the args is :", args)
for j := uint32(0); j < csubkey; j++ {
var buffer, uninstall_buf [syscall.MAX_LONG_PATH]uint16
n := uint32(len(buffer))
dwSize := uint32(len(uninstall_buf))
var display_name string
reg1 := regname + "\\" + list[j]
//fmt.Println("reg1 is ", reg1)
if reg1 == "Software\\Wow6432Node\\Xoreax\\IncrediBuild\\Builder" {
if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(reg1), 0, syscall.KEY_READ, &subtestkey) == nil {
e1 := syscall.RegQueryValueEx(subtestkey, syscall.StringToUTF16Ptr(args), nil, nil, (*byte)(unsafe.Pointer(&buffer[0])), &n)
if e1 != nil {
fmt.Println(e1)
}
result = syscall.UTF16ToString(buffer[:])
// fmt.Println(result, args)
return
}
}
if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, syscall.StringToUTF16Ptr(reg1), 0, syscall.KEY_READ, &subtestkey) == nil {
syscall.RegQueryValueEx(subtestkey, syscall.StringToUTF16Ptr("DisplayName"), nil, nil, (*byte)(unsafe.Pointer(&buffer[0])), &n)
display_name = syscall.UTF16ToString(buffer[:])
if strings.Contains(display_name, installer_name) {
if syscall.RegQueryValueEx(subtestkey, syscall.StringToUTF16Ptr(args), nil, nil, (*byte)(unsafe.Pointer(&uninstall_buf[0])), &dwSize) == nil {
result = syscall.UTF16ToString(uninstall_buf[:])
if result != "" {
return
}
}
}
}
defer syscall.RegCloseKey(subtestkey)
}
return
}
示例13: KeyInfo
func (c *Client) KeyInfo() (sessionKeySize uint32, sigAlg uint32, sigAlgName string, encAlg uint32, encAlgName string, err error) {
var ki _SecPkgContext_KeyInfo
ret := sspi.QueryContextAttributes(c.ctx.Handle, _SECPKG_ATTR_KEY_INFO, (*byte)(unsafe.Pointer(&ki)))
if ret != sspi.SEC_E_OK {
return 0, 0, "", 0, "", ret
}
defer sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ki.SignatureAlgorithmName)))
defer sspi.FreeContextBuffer((*byte)(unsafe.Pointer(ki.EncryptAlgorithmName)))
saname := syscall.UTF16ToString((*[2 << 20]uint16)(unsafe.Pointer(ki.SignatureAlgorithmName))[:])
eaname := syscall.UTF16ToString((*[2 << 20]uint16)(unsafe.Pointer(ki.EncryptAlgorithmName))[:])
return ki.KeySize, ki.SignatureAlgorithm, saname, ki.EncryptAlgorithm, eaname, nil
}
示例14: init
func init() {
var buf [4]uint16
win.GetLocaleInfo(win.LOCALE_USER_DEFAULT, win.LOCALE_SDECIMAL, &buf[0], int32(len(buf)))
decimalSepB = byte(buf[0])
decimalSepS = syscall.UTF16ToString(buf[0:1])
decimalSepUint16 = buf[0]
win.GetLocaleInfo(win.LOCALE_USER_DEFAULT, win.LOCALE_STHOUSAND, &buf[0], int32(len(buf)))
groupSepB = byte(buf[0])
groupSepS = syscall.UTF16ToString(buf[0:1])
groupSepUint16 = buf[0]
}
示例15: DirectSoundCaptureEnumerate
func DirectSoundCaptureEnumerate(dsEnumCallback func(guid *GUID, description string, module string) bool) error {
return dllDSResult(procDirectSoundCaptureEnumerate.Call(syscall.NewCallback(func(guid *GUID, description *[maxInt >> 1]uint16, module *[maxInt >> 1]uint16, context uintptr) int {
b := dsEnumCallback(
guid,
syscall.UTF16ToString(description[:]),
syscall.UTF16ToString(module[:]),
)
if b {
return 1
}
return 0
}), 0))
}