说明

golang mustloaddll示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: syscall

示例#1
文件: 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
文件: 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
文件: 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
文件: provisioning.go 项目: corentindrouet/community

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
文件: 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
文件: syscall_windows_test.go 项目: vinodpanicker/go

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
文件: 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
文件: 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
文件: 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
文件: version_dump_windows.go 项目: nikyoudale/agent

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
文件: 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
文件: 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
文件: 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
文件: fileutil_windows.go 项目: aws/amazon-ssm-agent

// 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
文件: 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
文件: 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
文件: main.go 项目: ludovicdeluna/go

func main() {

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

}

示例#18
文件: 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
文件: 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
文件: 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
文件: 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
文件: syscall_windows_test.go 项目: wheelcomplex/go-1

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
文件: password_reader_windows.go 项目: hpcloud/termui

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
文件: 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
文件: 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
文件: 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
文件: 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
文件: 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
文件: 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
文件: 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")
}