本文整理匯總了Golang中syscall.UTF16FromString函數的典型用法代碼示例。如果您正苦於以下問題:Golang UTF16FromString函數的具體用法?Golang UTF16FromString怎麽用?Golang UTF16FromString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了UTF16FromString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AcquireUserCredentials
// AcquireUserCredentials acquires credentials of user described by
// domain, username and password. These will be used by the client to
// authenticate itself to the server. It will also be used by the
// server to impersonate the user.
func AcquireUserCredentials(domain, username, password string) (*sspi.Credentials, error) {
if len(domain) == 0 {
return nil, errors.New("domain parameter cannot be empty")
}
if len(username) == 0 {
return nil, errors.New("username parameter cannot be empty")
}
d, err := syscall.UTF16FromString(domain)
if err != nil {
return nil, err
}
u, err := syscall.UTF16FromString(username)
if err != nil {
return nil, err
}
var p []uint16
var plen uint32
if len(password) > 0 {
p, err = syscall.UTF16FromString(password)
if err != nil {
return nil, err
}
plen = uint32(len(p) - 1) // do not count terminating 0
}
ai := _SEC_WINNT_AUTH_IDENTITY{
User: &u[0],
UserLength: uint32(len(u) - 1), // do not count terminating 0
Domain: &d[0],
DomainLength: uint32(len(d) - 1), // do not count terminating 0
Password: &p[0],
PasswordLength: plen,
Flags: _SEC_WINNT_AUTH_IDENTITY_UNICODE,
}
return acquireCredentials(sspi.SECPKG_CRED_OUTBOUND, &ai)
}
示例2: NewClientContext
// NewClientContext creates new client context. It uses client
// credentials cred generated by AcquireCurrentUserCredentials or
// AcquireUserCredentials and SPN to start client Negotiate
// negotiation sequence. targetName is the service principal name
// (SPN) or the security context of the destination server.
// NewClientContext returns new token to be sent to the server.
func NewClientContext(cred *sspi.Credentials, targetName string) (cc *ClientContext, outputToken []byte, err error) {
var tname *uint16
if len(targetName) > 0 {
p, err2 := syscall.UTF16FromString(targetName)
if err2 != nil {
return nil, nil, err2
}
if len(p) > 0 {
tname = &p[0]
}
}
otoken := make([]byte, PackageInfo.MaxToken)
c := sspi.NewClientContext(cred, sspi.ISC_REQ_CONNECTION)
authCompleted, n, err2 := updateContext(c, otoken, nil, tname)
if err2 != nil {
return nil, nil, err2
}
if authCompleted {
c.Release()
return nil, nil, errors.New("negotiate authentication should not be completed yet")
}
if n == 0 {
c.Release()
return nil, nil, errors.New("negotiate token should not be empty")
}
otoken = otoken[:n]
return &ClientContext{sctxt: c, targetName: tname}, otoken, nil
}
示例3: SetText
// SetText sets the current text data of the clipboard.
func (c *ClipboardService) SetText(s string) error {
return c.withOpenClipboard(func() error {
utf16, err := syscall.UTF16FromString(s)
if err != nil {
return err
}
hMem := win.GlobalAlloc(win.GMEM_MOVEABLE, uintptr(len(utf16)*2))
if hMem == 0 {
return lastError("GlobalAlloc")
}
p := win.GlobalLock(hMem)
if p == nil {
return lastError("GlobalLock()")
}
win.MoveMemory(p, unsafe.Pointer(&utf16[0]), uintptr(len(utf16)*2))
win.GlobalUnlock(hMem)
if 0 == win.SetClipboardData(win.CF_UNICODETEXT, win.HANDLE(hMem)) {
// We need to free hMem.
defer win.GlobalFree(hMem)
return lastError("SetClipboardData")
}
// The system now owns the memory referred to by hMem.
return nil
})
}
示例4: setStringValue
func (k Key) setStringValue(name string, valtype uint32, value string) error {
v, err := syscall.UTF16FromString(value)
if err != nil {
return err
}
buf := (*[1 << 10]byte)(unsafe.Pointer(&v[0]))[:len(v)*2]
return k.setValue(name, valtype, buf)
}
示例5: convertToUTF16
// convertToUTF16 converts the utf8 string to utf16
func convertToUTF16(a string) ([]byte, error) {
u16, err := syscall.UTF16FromString(a)
if err != nil {
return nil, errors.Annotate(err, "Failed to convert string to UTF16")
}
buf := &bytes.Buffer{}
if err := binary.Write(buf, binary.LittleEndian, u16); err != nil {
return nil, errors.Annotate(err, "Failed to convert UTF16 to bytes")
}
return buf.Bytes(), nil
}
示例6: OpenForBackup
// OpenForBackup opens a file or directory, potentially skipping access checks if the backup
// or restore privileges have been acquired.
//
// If the file opened was a directory, it cannot be used with Readdir().
func OpenForBackup(path string, access uint32, share uint32, createmode uint32) (*os.File, error) {
winPath, err := syscall.UTF16FromString(path)
if err != nil {
return nil, err
}
h, err := syscall.CreateFile(&winPath[0], access, share, nil, createmode, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
if err != nil {
err = &os.PathError{Op: "open", Path: path, Err: err}
return nil, err
}
return os.NewFile(uintptr(h), path), nil
}
示例7: openFileOrDir
func openFileOrDir(path string, mode uint32, createDisposition uint32) (file *os.File, err error) {
winPath, err := syscall.UTF16FromString(path)
if err != nil {
return
}
h, err := syscall.CreateFile(&winPath[0], mode, syscall.FILE_SHARE_READ, nil, createDisposition, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
if err != nil {
err = &os.PathError{"open", path, err}
return
}
file = os.NewFile(uintptr(h), path)
return
}
示例8: newWatched
// newWatched creates a new watched instance. It splits the filter variable into
// two parts. The first part is responsible for watching all events which can be
// created for a file in watched directory structure and the second one watches
// only directory Create/Remove actions. If all operations succeed, the Create
// message is sent to I/O completion port queue for further processing.
func newWatched(cph syscall.Handle, filter uint32, recursive bool,
path string) (wd *watched, err error) {
wd = &watched{
filter: filter,
recursive: recursive,
}
if wd.pathw, err = syscall.UTF16FromString(path); err != nil {
return
}
if err = wd.recreate(cph); err != nil {
return
}
return wd, nil
}
示例9: SetPrefix
// SetPrefix sets the text that appears in the NumberEdit before the number.
func (ne *NumberEdit) SetPrefix(prefix string) error {
p, err := syscall.UTF16FromString(prefix)
if err != nil {
return err
}
old := ne.edit.prefix
ne.edit.prefix = p[:len(p)-1]
if err := ne.edit.setTextFromValue(ne.edit.value); err != nil {
ne.edit.prefix = old
return err
}
return nil
}
示例10: SetSuffix
// SetSuffix sets the text that appears in the NumberEdit after the number.
func (ne *NumberEdit) SetSuffix(suffix string) error {
s, err := syscall.UTF16FromString(suffix)
if err != nil {
return err
}
old := ne.edit.suffix
ne.edit.suffix = s[:len(s)-1]
if err := ne.edit.setTextFromValue(ne.edit.value); err != nil {
ne.edit.suffix = old
return err
}
return nil
}
示例11: toLong
func toLong(path string) (string, error) {
p, err := syscall.UTF16FromString(path)
if err != nil {
return "", err
}
b := p // GetLongPathName says we can reuse buffer
n := uint32(len(b))
for {
n, err = syscall.GetLongPathName(&p[0], &b[0], uint32(len(b)))
if err != nil {
return "", err
}
if n <= uint32(len(b)) {
return syscall.UTF16ToString(b[:n]), nil
}
b = make([]uint16, n)
}
}
示例12: toShort
func toShort(path string) (string, error) {
p, err := syscall.UTF16FromString(path)
if err != nil {
return "", err
}
b := p // GetShortPathName says we can reuse buffer
n, err := syscall.GetShortPathName(&p[0], &b[0], uint32(len(b)))
if err != nil {
return "", err
}
if n > uint32(len(b)) {
b = make([]uint16, n)
if _, err = syscall.GetShortPathName(&p[0], &b[0], uint32(len(b))); err != nil {
return "", err
}
}
return syscall.UTF16ToString(b), nil
}
示例13: Get
func (fg *fileGetCloserWithBackupPrivileges) Get(filename string) (io.ReadCloser, error) {
var f *os.File
// Open the file while holding the Windows backup privilege. This ensures that the
// file can be opened even if the caller does not actually have access to it according
// to the security descriptor.
err := winio.RunWithPrivilege(winio.SeBackupPrivilege, func() error {
path := longpath.AddPrefix(filepath.Join(fg.path, filename))
p, err := syscall.UTF16FromString(path)
if err != nil {
return err
}
h, err := syscall.CreateFile(&p[0], syscall.GENERIC_READ, syscall.FILE_SHARE_READ, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
if err != nil {
return &os.PathError{Op: "open", Path: path, Err: err}
}
f = os.NewFile(uintptr(h), path)
return nil
})
return f, err
}
示例14: longPath
// longPath is copied over from the symlink package. This should be removed
// if we add it to gc or in some other convenience package
func longPath(path string) ([]uint16, error) {
pathp, err := syscall.UTF16FromString(path)
if err != nil {
return nil, err
}
longp := pathp
n, err := syscall.GetLongPathName(&pathp[0], &longp[0], uint32(len(longp)))
if err != nil {
return nil, err
}
if n > uint32(len(longp)) {
longp = make([]uint16, n)
n, err = syscall.GetLongPathName(&pathp[0], &longp[0], uint32(len(longp)))
if err != nil {
return nil, err
}
}
longp = longp[:n]
return longp, nil
}
示例15: Start
// Adds the notification icon and starts handling the mouse
// interaction with the icon.
// Calls to this function will block until the Stop() function
// will be called from another goroutine/thread.
// Returns an error, if adding the notify icons fails.
func (t *_NotifyIcon) Start() (err error) {
log.Println("Creating notification icon")
tooltipUtf16, _ := syscall.UTF16FromString(t.tooltip)
t.nid.CbSize = w32.DWORD(unsafe.Sizeof(&t.nid))
t.nid.HWnd = t.hwnd
t.nid.UFlags = _NIF_MESSAGE | _NIF_ICON | _NIF_TIP
t.nid.UID = niUID
t.nid.UCallbackMessage = niCallbackMessage
copy(t.nid.SzTip[:], tooltipUtf16)
err = shellNotifyIcon(_NIM_ADD, &t.nid)
if err != nil {
return
}
var msg w32.MSG
for w32.GetMessage(&msg, t.hwnd, uint32(0), uint32(0)) != 0 {
w32.TranslateMessage(&msg)
w32.DispatchMessage(&msg)
}
return nil
}