コード例 #1
0
ファイル: service.go プロジェクト: eswdd/bosun
func init() {
	k := syscall.MustLoadDLL("kernel32.dll")
	cSetEvent = k.MustFindProc("SetEvent").Addr()
	cWaitForSingleObject = k.MustFindProc("WaitForSingleObject").Addr()
	a := syscall.MustLoadDLL("advapi32.dll")
	cRegisterServiceCtrlHandlerW = a.MustFindProc("RegisterServiceCtrlHandlerW").Addr()
}
コード例 #2
0
ファイル: aapi.go プロジェクト: CodyGuo/xcgui
// 1.初始化UI库
func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	runtime.LockOSThread()

	if FileExist(xcDll) {
		xcDLL = syscall.MustLoadDLL(xcDll)
	} else if FileExist("lib/" + xcDll) {
		xcDLL = syscall.MustLoadDLL("lib/" + xcDll)
	} else if FileExist("../lib/" + xcDll) {
		xcDLL = syscall.MustLoadDLL("../lib/" + xcDll)
	} else if FileExist("../../lib/" + xcDll) {
		xcDLL = syscall.MustLoadDLL("../../lib/" + xcDll)
	} else {
		// 下载XCGUI.dll
		downLoadXCGUIDll()

		if FileExist(xcDll) {
			xcDLL = syscall.MustLoadDLL(xcDll)
		} else {
			panic("xcgui library not found,XCGUI.dll or ./lib/XCGUI.dll or ../lib/XCGUI.dll.")
		}

	}

	// Functions
	xC_UnicodeToAnsi = xcDLL.MustFindProc("XC_UnicodeToAnsi")
	xC_AnsiToUnicode = xcDLL.MustFindProc("XC_AnsiToUnicode")
	xC_DebugToFileInfo = xcDLL.MustFindProc("XC_DebugToFileInfo")
	xC_IsHELE = xcDLL.MustFindProc("XC_IsHELE")
	xC_IsHWINDOW = xcDLL.MustFindProc("XC_IsHWINDOW")
	xC_IsShape = xcDLL.MustFindProc("XC_IsShape")
	xC_IsHXCGUI = xcDLL.MustFindProc("XC_IsHXCGUI")
	xC_hWindowFromHWnd = xcDLL.MustFindProc("XC_hWindowFromHWnd")
	xC_IsSViewExtend = xcDLL.MustFindProc("XC_IsSViewExtend")
	xC_GetObjectType = xcDLL.MustFindProc("XC_GetObjectType")
	xC_GetObjectByID = xcDLL.MustFindProc("XC_GetObjectByID")
	xC_GetResIDValue = xcDLL.MustFindProc("XC_GetResIDValue")
	xC_SetPaintFrequency = xcDLL.MustFindProc("XC_SetPaintFrequency")
	xC_RectInRect = xcDLL.MustFindProc("XC_RectInRect")
	xC_CombineRect = xcDLL.MustFindProc("XC_CombineRect")
	xC_ShowLayoutFrame = xcDLL.MustFindProc("XC_ShowLayoutFrame")
	xC_SetLayoutFrameColor = xcDLL.MustFindProc("XC_SetLayoutFrameColor")
	xC_EnableErrorMessageBox = xcDLL.MustFindProc("XC_EnableErrorMessageBox")
	xInitXCGUI = xcDLL.MustFindProc("XInitXCGUI")
	xRunXCGUI = xcDLL.MustFindProc("XRunXCGUI")
	xExitXCGUI = xcDLL.MustFindProc("XExitXCGUI")

	ret, _, _ := xInitXCGUI.Call(StringToUintPtr("XCGUI Library For Go"))
	// XCGUI的返回值: true 为 1 ,false 为 0
	if ret != TRUE {
		panic("XInitXCGUI call failed.")
	}
}
コード例 #3
0
ファイル: api.go プロジェクト: henrylee2cn/xcgui
// 1.初始化UI库
func init() {
	runtime.LockOSThread()

	if FileExist(xcDll) {
		XCDLL = syscall.MustLoadDLL(xcDll)
	} else if FileExist("lib/" + xcDll) {
		XCDLL = syscall.MustLoadDLL("lib/" + xcDll)
	} else if FileExist("../lib/" + xcDll) {
		XCDLL = syscall.MustLoadDLL("../lib/" + xcDll)
	} else {
		panic("xcgui library not found")
	}

	// Functions
	xC_UnicodeToAnsi = XCDLL.MustFindProc("XC_UnicodeToAnsi")
	xC_AnsiToUnicode = XCDLL.MustFindProc("XC_AnsiToUnicode")
	xC_DebugToFileInfo = XCDLL.MustFindProc("XC_DebugToFileInfo")
	xC_IsHELE = XCDLL.MustFindProc("XC_IsHELE")
	xC_IsHWINDOW = XCDLL.MustFindProc("XC_IsHWINDOW")
	xC_IsShape = XCDLL.MustFindProc("XC_IsShape")
	xC_IsHXCGUI = XCDLL.MustFindProc("XC_IsHXCGUI")
	xC_hWindowFromHWnd = XCDLL.MustFindProc("XC_hWindowFromHWnd")
	xC_IsSViewExtend = XCDLL.MustFindProc("XC_IsSViewExtend")
	xC_GetObjectType = XCDLL.MustFindProc("XC_GetObjectType")
	xC_GetObjectByID = XCDLL.MustFindProc("XC_GetObjectByID")
	xC_RectInRect = XCDLL.MustFindProc("XC_RectInRect")
	xC_CombineRect = XCDLL.MustFindProc("XC_CombineRect")
	xC_ShowLayoutFrame = XCDLL.MustFindProc("XC_ShowLayoutFrame")
	xC_SetLayoutFrameColor = XCDLL.MustFindProc("XC_SetLayoutFrameColor")
	xC_EnableErrorMessageBox = XCDLL.MustFindProc("XC_EnableErrorMessageBox")
	xInitXCGUI = XCDLL.MustFindProc("XInitXCGUI")
	xRunXCGUI = XCDLL.MustFindProc("XRunXCGUI")
	xExitXCGUI = XCDLL.MustFindProc("XExitXCGUI")

	// *******************************************
	// @Author: cody.guo
	// @Date: 2015-11-7 09:40:36
	// @Function: XInitXCGUI
	// @Description: 初始化界面库.
	// @Calls: XInitXCGUI
	// @Input: pText 保留参数.
	// @Return: 成功返回TRUE否则返回FALSE.
	// *******************************************
	ret, _, _ := xInitXCGUI.Call(StringToUintPtr("XCGUI Library For Go"))
	// XCGUI的返回值: true 为 1 ,false 为 0
	if ret != TRUE {
		panic("XInitXCGUI call failed.")
	}
}
コード例 #4
0
func executeCommandAsAdmin(cmd string) {
	var si startupinfo
	var handle HANDLE
	var pi processinfo

	si.cb = uint32(unsafe.Sizeof(si))

	a := syscall.MustLoadDLL("advapi32.dll")
	LogonUserW := a.MustFindProc("LogonUserW")
	r1, r2, lastError := LogonUserW.Call(
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(adminUsername))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(domain))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(adminPassword))),
		LOGON32_LOGON_INTERACTIVE,
		LOGON32_PROVIDER_DEFAULT,
		uintptr(unsafe.Pointer(&handle)),
	)
	log.Error(r1)
	log.Error(r2)
	log.Error(lastError)

	CreateProcessAsUser := a.MustFindProc("CreateProcessAsUserW")
	r1, r2, lastError = CreateProcessAsUser.Call(
		uintptr(unsafe.Pointer(handle)),
		uintptr(unsafe.Pointer(nil)),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(cmd))),
		uintptr(unsafe.Pointer(nil)),
		uintptr(unsafe.Pointer(nil)),
		uintptr(0),
		uintptr(unsafe.Pointer(nil)),
		uintptr(unsafe.Pointer(nil)),
		uintptr(unsafe.Pointer(nil)),
		uintptr(unsafe.Pointer(&si)),
		uintptr(unsafe.Pointer(&pi)),
	)
	log.Error(r1)
	log.Error(r2)
	log.Error(lastError)

	b := syscall.MustLoadDLL("Kernel32.dll")
	CloseHandle := b.MustFindProc("CloseHandle")
	r1, r2, lastError = CloseHandle.Call(
		uintptr(unsafe.Pointer(handle)),
	)
	log.Error(r1)
	log.Error(r2)
	log.Error(lastError)
}
コード例 #5
0
ファイル: facts_windows.go プロジェクト: enr/terminus
func (f *SystemFacts) getOSRelease(wg *sync.WaitGroup) {
	defer wg.Done()
	log.Println("getOSRelease NOT fully implemented")

	f.mu.Lock()
	defer f.mu.Unlock()

	dll := syscall.MustLoadDLL("kernel32.dll")
	p, err := dll.FindProc("GetVersion")
	if err != nil {
		log.Println(err.Error())
		return
	}
	// The returned error is always non-nil
	v, _, err := p.Call()
	if v == 0 && err != nil {
		log.Println(err.Error())
		return
	}
	major := int(byte(v))
	minor := int(uint8(v >> 8))
	build := int(uint16(v >> 16))

	f.OSRelease.Name = "windows"
	f.OSRelease.ID = "windows"
	f.OSRelease.PrettyName = fmt.Sprintf("Windows version %d.%d (Build %d)", major, minor, build)
	f.OSRelease.Version = fmt.Sprintf("%d", major)
	f.OSRelease.VersionID = fmt.Sprintf("%d.%d.%d", major, minor, build)
	f.OSRelease.CodeName = ""
	return
}
コード例 #6
0
func TestReturnAfterStackGrowInCallback(t *testing.T) {

	const src = `
#include <stdint.h>
#include <windows.h>

typedef uintptr_t __stdcall (*callback)(uintptr_t);

uintptr_t cfunc(callback f, uintptr_t n) {
   uintptr_t r;
   r = f(n);
   SetLastError(333);
   return r;
}
`
	tmpdir, err := ioutil.TempDir("", "TestReturnAfterStackGrowInCallback")
	if err != nil {
		t.Fatal("TempDir failed: ", err)
	}
	defer os.RemoveAll(tmpdir)

	srcname := "mydll.c"
	err = ioutil.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0)
	if err != nil {
		t.Fatal(err)
	}
	outname := "mydll.dll"
	cmd := exec.Command("gcc", "-shared", "-s", "-Werror", "-o", outname, srcname)
	cmd.Dir = tmpdir
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatalf("failed to build dll: %v - %v", err, string(out))
	}
	dllpath := filepath.Join(tmpdir, outname)

	dll := syscall.MustLoadDLL(dllpath)
	defer dll.Release()

	proc := dll.MustFindProc("cfunc")

	cb := syscall.NewCallback(func(n uintptr) uintptr {
		forceStackCopy()
		return n
	})

	// Use a new goroutine so that we get a small stack.
	type result struct {
		r   uintptr
		err syscall.Errno
	}
	c := make(chan result)
	go func() {
		r, _, err := proc.Call(cb, 100)
		c <- result{r, err.(syscall.Errno)}
	}()
	want := result{r: 100, err: 333}
	if got := <-c; got != want {
		t.Errorf("got %d want %d", got, want)
	}
}
コード例 #7
0
ファイル: passphrase_windows.go プロジェクト: sf1/cryptic
func init() {
	if kernel32.GetConsoleMode == nil {
		dll := syscall.MustLoadDLL("kernel32.dll")
		kernel32.GetConsoleMode = dll.MustFindProc("GetConsoleMode")
		kernel32.SetConsoleMode = dll.MustFindProc("SetConsoleMode")
	}
}
コード例 #8
0
ファイル: beep.go プロジェクト: haohuoyao/files
func main() {
	a := flag.Int("a", 1000, "")
	b := flag.Int("b", 2000, "") // two seconds
	flag.Parse()
	k := syscall.MustLoadDLL("kernel32.dll")
	k.MustFindProc("Beep").Call(uintptr(*a), uintptr(*b))
}
コード例 #9
0
ファイル: SHEmptyRecycleBin.go プロジェクト: ludovicdeluna/go
func main() {
	d := syscall.MustLoadDLL("shell32.dll")
	SHEmptyRecycleBinProc := d.MustFindProc("SHEmptyRecycleBinW")
	SHEmptyRecycleBinProc.Call(uintptr(0), uintptr(0), SHERB_NOCONFIRMATION)
	fmt.Printf("cleaned")

}
コード例 #10
0
func VersionDump() (string, error) {
	dll := syscall.MustLoadDLL("kernel32.dll")
	p := dll.MustFindProc("GetVersion")
	v, _, _ := p.Call()

	return fmt.Sprintf("Windows version %d.%d (Build %d)\n", byte(v), uint8(v>>8), uint16(v>>16)), nil
}
コード例 #11
0
ファイル: winpath.go プロジェクト: serverhorror/mvln
func EvaluateTargets(t []string) string {

	h := syscall.MustLoadDLL("kernel32.dll")
	c := h.MustFindProc("GetDiskFreeSpaceExW")

	var maxFreeBytes uint64
	var bestTarget string

	for _, p := range t {
		var freeBytes uint64

		vol := filepath.VolumeName(p)

		ptr1 := unsafe.Pointer(syscall.StringToUTF16Ptr(vol))
		ptr2 := unsafe.Pointer(&freeBytes)

		c.Call(
			uintptr(ptr1),
			uintptr(ptr2),
			uintptr(0),
			uintptr(0),
		)

		if freeBytes > maxFreeBytes {
			maxFreeBytes = freeBytes
			bestTarget = p
		}
	}
	return bestTarget
}
コード例 #12
0
ファイル: helper_windows.go プロジェクト: juqkai/gopm
func volumnType(dir string) string {
	pd := dir[:3]
	dll := syscall.MustLoadDLL("kernel32.dll")
	GetVolumeInformation := dll.MustFindProc("GetVolumeInformationW")

	var volumeNameSize uint32 = 260
	var nFileSystemNameSize, lpVolumeSerialNumber uint32
	var lpFileSystemFlags, lpMaximumComponentLength uint32
	var lpFileSystemNameBuffer, volumeName [260]byte
	var ps *uint16 = syscall.StringToUTF16Ptr(pd)

	_, _, _ = GetVolumeInformation.Call(uintptr(unsafe.Pointer(ps)),
		uintptr(unsafe.Pointer(&volumeName)),
		uintptr(volumeNameSize),
		uintptr(unsafe.Pointer(&lpVolumeSerialNumber)),
		uintptr(unsafe.Pointer(&lpMaximumComponentLength)),
		uintptr(unsafe.Pointer(&lpFileSystemFlags)),
		uintptr(unsafe.Pointer(&lpFileSystemNameBuffer)),
		uintptr(unsafe.Pointer(&nFileSystemNameSize)), 0)

	var bytes []byte
	if lpFileSystemNameBuffer[6] == 0 {
		bytes = []byte{lpFileSystemNameBuffer[0], lpFileSystemNameBuffer[2],
			lpFileSystemNameBuffer[4]}
	} else {
		bytes = []byte{lpFileSystemNameBuffer[0], lpFileSystemNameBuffer[2],
			lpFileSystemNameBuffer[4], lpFileSystemNameBuffer[6]}
	}

	return string(bytes)
}
コード例 #13
0
ファイル: syscall_windows.go プロジェクト: RajibTheKing/gcc
func RaiseException() {
	const EXCEPTION_NONCONTINUABLE = 1
	mod := syscall.MustLoadDLL("kernel32.dll")
	proc := mod.MustFindProc("RaiseException")
	proc.Call(0xbad, EXCEPTION_NONCONTINUABLE, 0, 0)
	println("RaiseException should not return")
}
コード例 #14
0
// GetDiskSpaceInfo returns available, free, and total bytes respectively from system disk space
func GetDiskSpaceInfo() (diskSpaceInfo DiskSpaceInfo, err error) {
	var wd string
	var availBytes, totalBytes, freeBytes int64

	// Get a rooted path name
	if wd, err = os.Getwd(); err != nil {
		return
	}

	// Load kernel32.dll and find GetDiskFreeSpaceEX function
	getDiskFreeSpace := syscall.MustLoadDLL("kernel32.dll").MustFindProc("GetDiskFreeSpaceExW")

	// Get the available bytes (for arguments, GetDiskFreeSpace function takes dir name, avail, total, and free respectively)
	_, _, err = getDiskFreeSpace.Call(
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(wd))),
		uintptr(unsafe.Pointer(&availBytes)),
		uintptr(unsafe.Pointer(&totalBytes)),
		uintptr(unsafe.Pointer(&freeBytes)))

	return DiskSpaceInfo{
		AvailBytes: availBytes,
		FreeBytes:  freeBytes,
		TotalBytes: totalBytes,
	}, nil
}
コード例 #15
0
ファイル: kernel32.go プロジェクト: henrylee2cn/xcgui
func init() {
	// Library
	libkernel32 = syscall.MustLoadDLL("kernel32.dll")

	// Functions
	closeHandle = libkernel32.MustFindProc("CloseHandle")
	fileTimeToSystemTime = libkernel32.MustFindProc("FileTimeToSystemTime")
	getConsoleTitle = libkernel32.MustFindProc("GetConsoleTitleW")
	getConsoleWindow = libkernel32.MustFindProc("GetConsoleWindow")
	getLastError = libkernel32.MustFindProc("GetLastError")
	getLocaleInfo = libkernel32.MustFindProc("GetLocaleInfoW")
	getLogicalDriveStrings = libkernel32.MustFindProc("GetLogicalDriveStringsW")
	getModuleHandle = libkernel32.MustFindProc("GetModuleHandleW")
	getNumberFormat = libkernel32.MustFindProc("GetNumberFormatW")
	getProfileString = libkernel32.MustFindProc("GetProfileStringW")
	getThreadLocale = libkernel32.MustFindProc("GetThreadLocale")
	getThreadUILanguage = libkernel32.MustFindProc("GetThreadUILanguage")
	getVersion = libkernel32.MustFindProc("GetVersion")
	globalAlloc = libkernel32.MustFindProc("GlobalAlloc")
	globalFree = libkernel32.MustFindProc("GlobalFree")
	globalLock = libkernel32.MustFindProc("GlobalLock")
	globalUnlock = libkernel32.MustFindProc("GlobalUnlock")
	moveMemory = libkernel32.MustFindProc("RtlMoveMemory")
	mulDiv = libkernel32.MustFindProc("MulDiv")
	setLastError = libkernel32.MustFindProc("SetLastError")
	systemTimeToFileTime = libkernel32.MustFindProc("SystemTimeToFileTime")

}
コード例 #16
0
ファイル: stat_windows.go プロジェクト: yrashk/minio
// GetInfo returns total and free bytes available in a directory, e.g. `C:\`.
// It returns free space available to the user (including quota limitations)
//
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
func GetInfo(path string) (info Info, err error) {
	// Stat to know if the path exists.
	if _, err = os.Stat(path); err != nil {
		return Info{}, err
	}

	dll := syscall.MustLoadDLL("kernel32.dll")
	// https://msdn.microsoft.com/en-us/library/windows/desktop/aa364937(v=vs.85).aspx
	// Retrieves information about the amount of space that is available on a disk volume,
	// which is the total amount of space, the total amount of free space, and the total
	// amount of free space available to the user that is associated with the calling thread.
	GetDiskFreeSpaceEx := dll.MustFindProc("GetDiskFreeSpaceExW")

	lpFreeBytesAvailable := int64(0)
	lpTotalNumberOfBytes := int64(0)
	lpTotalNumberOfFreeBytes := int64(0)

	// Extract values safely
	// BOOL WINAPI GetDiskFreeSpaceEx(
	// _In_opt_  LPCTSTR         lpDirectoryName,
	// _Out_opt_ PULARGE_INTEGER lpFreeBytesAvailable,
	// _Out_opt_ PULARGE_INTEGER lpTotalNumberOfBytes,
	// _Out_opt_ PULARGE_INTEGER lpTotalNumberOfFreeBytes
	// );
	_, _, _ = GetDiskFreeSpaceEx.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)))
	info = Info{}
	info.Total = int64(lpTotalNumberOfBytes)
	info.Free = int64(lpFreeBytesAvailable)
	info.FSType = getFSType(path)
	return info, nil
}
コード例 #17
0
ファイル: main.go プロジェクト: ludovicdeluna/go
func main() {

	dhv := syscall.MustLoadDLL("dhv.dll")
	hi := dhv.MustFindProc("hi")
	s, _, _ := hi.Call()
	println(s)

}
コード例 #18
0
ファイル: user32.go プロジェクト: henrylee2cn/xcgui
func init() {
	User32 = syscall.MustLoadDLL("User32.dll")
	MessageBoxW = User32.MustFindProc("MessageBoxW")
	SendMessageW = User32.MustFindProc("SendMessageW")
	GetMessageW = User32.MustFindProc("GetMessageW")
	TranslateMessageW = User32.MustFindProc("TranslateMessage")
	DispatchMessageW = User32.MustFindProc("DispatchMessageW")
}
コード例 #19
0
ファイル: crash_windows.go プロジェクト: haowang1013/kaiju
func setCrashLogFile(f *os.File) {
	kernel32 := syscall.MustLoadDLL("kernel32.dll")
	ph := kernel32.MustFindProc("SetStdHandle")
	err = winSetStdHandle(ph, syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd()))
	if err != nil {
		Panicf("Error setting up winSetStdHandle: %s", err)
	}
}
コード例 #20
0
ファイル: idle.go プロジェクト: rwhitmire/idle
func main() {
	lastInputInfo.cbSize = uint32(unsafe.Sizeof(lastInputInfo))

	user32 := syscall.MustLoadDLL("user32.dll")
	kernel32 := syscall.MustLoadDLL("Kernel32.dll")
	getLastInputInfo := user32.MustFindProc("GetLastInputInfo")
	getTickCount := kernel32.MustFindProc("GetTickCount")

	tickCount, _, _ := getTickCount.Call()

	idle, _, _ := getLastInputInfo.Call(uintptr(unsafe.Pointer(&lastInputInfo)))

	if idle == 0 || tickCount == 0 {
		panic("It didn't work")
	}

	os.Stdout.Write([]byte(strconv.FormatInt((int64(tickCount) - int64(lastInputInfo.dwTime)), 10)))
}
コード例 #21
0
ファイル: user32.go プロジェクト: maxid/xcgui
func init() {
	user32 = syscall.MustLoadDLL("User32.dll")

	clientToScreen = user32.MustFindProc("ClientToScreen")
	messageBox = user32.MustFindProc("MessageBoxW")
	sendMessage = user32.MustFindProc("SendMessageW")
	getMessage = user32.MustFindProc("GetMessageW")
	translateMessage = user32.MustFindProc("TranslateMessage")
	dispatchMessage = user32.MustFindProc("DispatchMessageW")
}
コード例 #22
0
func (test *cbTest) run(t *testing.T, dllpath string) {
	dll := syscall.MustLoadDLL(dllpath)
	defer dll.Release()
	cb := cbFuncs[test.n]
	stdcall := syscall.NewCallback(cb)
	f := cbDLLFunc(test.n)
	test.runOne(t, dll, f.stdcallName(), stdcall)
	cdecl := syscall.NewCallbackCDecl(cb)
	test.runOne(t, dll, f.cdeclName(), cdecl)
}
コード例 #23
0
func setConsoleMode(console syscall.Handle, mode uint32) (err error) {
	dll := syscall.MustLoadDLL("kernel32")
	proc := dll.MustFindProc("SetConsoleMode")
	r, _, err := proc.Call(uintptr(console), uintptr(mode))

	if r == 0 {
		return err
	}
	return nil
}
コード例 #24
0
ファイル: os2_windows.go プロジェクト: QuocHuy7a10/Arianrhod
func getExecutable() string {
	var GetModuleFileNameW = syscall.MustLoadDLL("kernel32.dll").MustFindProc("GetModuleFileNameW")
	b := make([]uint16, 0x7FFF)
	r, _, _ := GetModuleFileNameW.Call(0, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)))
	n := uint32(r)
	if n == 0 {
		return ""
	}
	return string(utf16.Decode(b[:n]))
}
コード例 #25
0
ファイル: RegDeleteKeyW.go プロジェクト: ludovicdeluna/go
// C:\>reg add HKCU\google_test
//C:\>reg delete HKCU\google_test
func main() {
	var a = syscall.MustLoadDLL("advapi32")
	var regdeletekeyw = a.MustFindProc("RegDeleteKeyW")

	_, _, e1 := regdeletekeyw.Call(
		uintptr(HKEY_CURRENT_USER),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(`google_test`))),
	)
	f("%v", e1)

}
コード例 #26
0
ファイル: syscall_windows_test.go プロジェクト: achanda/go
func TestFloatArgs(t *testing.T) {
	if _, err := exec.LookPath("gcc"); err != nil {
		t.Skip("skipping test: gcc is missing")
	}
	if runtime.GOARCH != "amd64" {
		t.Skipf("skipping test: GOARCH=%s", runtime.GOARCH)
	}

	const src = `
#include <stdint.h>
#include <windows.h>

uintptr_t cfunc(uintptr_t a, double b, float c, double d) {
	if (a == 1 && b == 2.2 && c == 3.3f && d == 4.4e44) {
		return 1;
	}
	return 0;
}
`
	tmpdir, err := ioutil.TempDir("", "TestFloatArgs")
	if err != nil {
		t.Fatal("TempDir failed: ", err)
	}
	defer os.RemoveAll(tmpdir)

	srcname := "mydll.c"
	err = ioutil.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0)
	if err != nil {
		t.Fatal(err)
	}
	outname := "mydll.dll"
	cmd := exec.Command("gcc", "-shared", "-s", "-Werror", "-o", outname, srcname)
	cmd.Dir = tmpdir
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatalf("failed to build dll: %v - %v", err, string(out))
	}
	dllpath := filepath.Join(tmpdir, outname)

	dll := syscall.MustLoadDLL(dllpath)
	defer dll.Release()

	proc := dll.MustFindProc("cfunc")

	r, _, err := proc.Call(
		1,
		uintptr(math.Float64bits(2.2)),
		uintptr(math.Float32bits(3.3)),
		uintptr(math.Float64bits(4.4e44)),
	)
	if r != 1 {
		t.Errorf("got %d want 1 (err=%v)", r, err)
	}
}
コード例 #27
0
ファイル: main.go プロジェクト: CodyGuo/Go-Cody
func main() {
	k32dll := syscall.MustLoadDLL("kernel32.dll")
	defer syscall.FreeLibrary(k32dll.Handle)

	getVersion, err := k32dll.FindProc("GetVersion")
	CheckError(err)

	ret, _, _ := getVersion.Call()
	printVersion(uint32(ret))

}
コード例 #28
0
ファイル: utils_windows.go プロジェクト: luffyhwl/gopark
func getPathFreeTotal(fpath string) (uint64, uint64) {
	h := syscall.MustLoadDLL("kernel32.dll")
	c := h.MustFindProc("GetDiskFreeSpaceExW")
	lpFreeBytesAvailable := uint64(0)
	lpTotalNumberOfBytes := uint64(0)
	lpTotalNumberOfFreeBytes := uint64(0)
	c.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(fpath))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)))
	return lpTotalNumberOfFreeBytes, lpTotalNumberOfBytes
}
コード例 #29
0
ファイル: main.go プロジェクト: CodyGuo/Go-Cody
func init() {
	dhnetsdkDll = syscall.MustLoadDLL("dhnetsdk.dll")

	client_Init = dhnetsdkDll.MustFindProc("CLIENT_Init")
	client_SetNetworkParam = dhnetsdkDll.MustFindProc("CLIENT_SetNetworkParam")
	client_LoginEx2 = dhnetsdkDll.MustFindProc("CLIENT_LoginEx2")
	client_Logout = dhnetsdkDll.MustFindProc("CLIENT_Logout")
	client_Cleanup = dhnetsdkDll.MustFindProc("CLIENT_Cleanup")
	client_SetDevConfig = dhnetsdkDll.MustFindProc("CLIENT_SetDevConfig")
	client_GetDevConfig = dhnetsdkDll.MustFindProc("CLIENT_GetDevConfig")
	client_GetLastError = dhnetsdkDll.MustFindProc("CLIENT_GetLastError")
	client_QuerySystemInfo = dhnetsdkDll.MustFindProc("CLIENT_QuerySystemInfo")
}
コード例 #30
0
ファイル: pdh.go プロジェクト: cxfksword/win
func init() {
	// Library
	libpdhDll = syscall.MustLoadDLL("pdh.dll")

	// Functions
	pdh_AddCounterW = libpdhDll.MustFindProc("PdhAddCounterW")
	pdh_AddEnglishCounterW, _ = libpdhDll.FindProc("PdhAddEnglishCounterW") // XXX: only supported on versions > Vista.
	pdh_CloseQuery = libpdhDll.MustFindProc("PdhCloseQuery")
	pdh_CollectQueryData = libpdhDll.MustFindProc("PdhCollectQueryData")
	pdh_GetFormattedCounterValue = libpdhDll.MustFindProc("PdhGetFormattedCounterValue")
	pdh_GetFormattedCounterArrayW = libpdhDll.MustFindProc("PdhGetFormattedCounterArrayW")
	pdh_OpenQuery = libpdhDll.MustFindProc("PdhOpenQuery")
	pdh_ValidatePathW = libpdhDll.MustFindProc("PdhValidatePathW")
}