Ejemplo n.º 1
0
func TestFormatMessage(t *testing.T) {
	dll := windows.MustLoadDLL("pdh.dll")

	pdhOpenQuery := func(datasrc *uint16, userdata uint32, query *windows.Handle) (errno uintptr) {
		r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhOpenQueryW").Addr(), 3, uintptr(unsafe.Pointer(datasrc)), uintptr(userdata), uintptr(unsafe.Pointer(query)))
		return r0
	}

	pdhCloseQuery := func(query windows.Handle) (errno uintptr) {
		r0, _, _ := syscall.Syscall(dll.MustFindProc("PdhCloseQuery").Addr(), 1, uintptr(query), 0, 0)
		return r0
	}

	var q windows.Handle
	name, err := windows.UTF16PtrFromString("no_such_source")
	if err != nil {
		t.Fatal(err)
	}
	errno := pdhOpenQuery(name, 0, &q)
	if errno == 0 {
		pdhCloseQuery(q)
		t.Fatal("PdhOpenQuery succeeded, but expected to fail.")
	}

	const flags uint32 = syscall.FORMAT_MESSAGE_FROM_HMODULE | syscall.FORMAT_MESSAGE_ARGUMENT_ARRAY | syscall.FORMAT_MESSAGE_IGNORE_INSERTS
	buf := make([]uint16, 300)
	_, err = windows.FormatMessage(flags, uintptr(dll.Handle), uint32(errno), 0, buf, nil)
	if err != nil {
		t.Fatal("FormatMessage for handle=%x and errno=%x failed: %v", dll.Handle, errno, err)
	}
}
Ejemplo n.º 2
0
	szOEMVxD    [_MAX_JOYSTICKOEMVXDNAME]uint16
}

type JOYINFOEX struct {
	dwSize         uint32
	dwFlags        uint32
	dwAxis         [_MAX_AXIS]uint32
	dwButtons      uint32
	dwButtonNumber uint32
	dwPOV          uint32
	dwReserved1    uint32
	dwReserved2    uint32
}

var (
	winmmdll      = windows.MustLoadDLL("Winmm.dll")
	joyGetPosEx   = winmmdll.MustFindProc("joyGetPosEx")
	joyGetDevCaps = winmmdll.MustFindProc("joyGetDevCapsW")
)

type axisLimit struct {
	min, max uint32
}

type joystickImpl struct {
	id           int
	axisCount    int
	povAxisCount int
	buttonCount  int
	name         string
	state        State
Ejemplo n.º 3
0
// +build windows

package storedir

import (
	"path/filepath"
	"unsafe"

	"golang.org/x/sys/windows"
)

var getDiskFreeSpaceExW = windows.MustLoadDLL("Kernel32.dll").MustFindProc("GetDiskFreeSpaceExW")

func (ds *Directory) FreeSpace(cancel <-chan struct{}) (int64, error) {
	dir, err := filepath.Abs(ds.Dir)
	if err != nil {
		return 0, err
	}

	// TODO: this doesn't look like it's safe under garbage collection
	var avail, total, free int64
	r1, _, err := getDiskFreeSpaceExW.Call(
		uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(dir))),
		uintptr(unsafe.Pointer(&avail)),
		uintptr(unsafe.Pointer(&total)),
		uintptr(unsafe.Pointer(&free)))
	if r1 == 0 {
		return 0, err
	}

	return free, nil
Ejemplo n.º 4
0
// Windows API functions for manipulating ACLs.
package api

import (
	"golang.org/x/sys/windows"
)

var advapi32 = windows.MustLoadDLL("advapi32.dll")