nativehttp

Simple interface to the native http client
Log | Files | Refs | README | LICENSE

windows.go (913B)


      1 //go:build windows
      2 
      3 package windows
      4 
      5 import "syscall"
      6 
      7 // UTF16PtrFromString returns pointer to the UTF-16 encoding of
      8 // the UTF-8 string s, with a terminating NUL added. If s
      9 // contains a NUL byte at any location, it returns (nil, syscall.EINVAL).
     10 func UTF16PtrFromString(s string) (*uint16, error) {
     11 	a, err := UTF16FromString(s)
     12 	if err != nil {
     13 		return nil, err
     14 	}
     15 	return &a[0], nil
     16 }
     17 
     18 // UTF16FromString returns the UTF-16 encoding of the UTF-8 string
     19 // s, with a terminating NUL added. If s contains a NUL byte at any
     20 // location, it returns (nil, syscall.EINVAL).
     21 func UTF16FromString(s string) ([]uint16, error) {
     22 	return syscall.UTF16FromString(s)
     23 }
     24 
     25 var (
     26 	modkernel32      = syscall.NewLazyDLL("kernel32")
     27 	procGetLastError = modkernel32.NewProc("GetLastError")
     28 )
     29 
     30 func GetLastError() (lasterr error) {
     31 	r0, _, _ := procGetLastError.Call()
     32 	if r0 != 0 {
     33 		lasterr = syscall.Errno(r0)
     34 	}
     35 	return
     36 }