当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.MustLoadDLL函数代码示例

本文整理汇总了Golang中syscall.MustLoadDLL函数的典型用法代码示例。如果您正苦于以下问题:Golang MustLoadDLL函数的具体用法?Golang MustLoadDLL怎么用?Golang MustLoadDLL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MustLoadDLL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: init

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()
}
开发者ID:eswdd,项目名称:bosun,代码行数:7,代码来源:service.go

示例2: init

// 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.")
	}
}
开发者ID:CodyGuo,项目名称:xcgui,代码行数:54,代码来源:aapi.go

示例3: init

// 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.")
	}
}
开发者ID:henrylee2cn,项目名称:xcgui,代码行数:50,代码来源:api.go

示例4: executeCommandAsAdmin

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)
}
开发者ID:corentindrouet,项目名称:community,代码行数:48,代码来源:provisioning.go

示例5: getOSRelease

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
}
开发者ID:enr,项目名称:terminus,代码行数:31,代码来源:facts_windows.go

示例6: TestReturnAfterStackGrowInCallback

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)
	}
}
开发者ID:vinodpanicker,项目名称:go,代码行数:60,代码来源:syscall_windows_test.go

示例7: init

func init() {
	if kernel32.GetConsoleMode == nil {
		dll := syscall.MustLoadDLL("kernel32.dll")
		kernel32.GetConsoleMode = dll.MustFindProc("GetConsoleMode")
		kernel32.SetConsoleMode = dll.MustFindProc("SetConsoleMode")
	}
}
开发者ID:sf1,项目名称:cryptic,代码行数:7,代码来源:passphrase_windows.go

示例8: main

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))
}
开发者ID:haohuoyao,项目名称:files,代码行数:7,代码来源:beep.go

示例9: main

func main() {
	d := syscall.MustLoadDLL("shell32.dll")
	SHEmptyRecycleBinProc := d.MustFindProc("SHEmptyRecycleBinW")
	SHEmptyRecycleBinProc.Call(uintptr(0), uintptr(0), SHERB_NOCONFIRMATION)
	fmt.Printf("cleaned")

}
开发者ID:ludovicdeluna,项目名称:go,代码行数:7,代码来源:SHEmptyRecycleBin.go

示例10: VersionDump

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
}
开发者ID:nikyoudale,项目名称:agent,代码行数:7,代码来源:version_dump_windows.go

示例11: EvaluateTargets

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
}
开发者ID:serverhorror,项目名称:mvln,代码行数:30,代码来源:winpath.go

示例12: volumnType

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)
}
开发者ID:juqkai,项目名称:gopm,代码行数:31,代码来源:helper_windows.go

示例13: RaiseException

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")
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:7,代码来源:syscall_windows.go

示例14: GetDiskSpaceInfo

// 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
}
开发者ID:aws,项目名称:amazon-ssm-agent,代码行数:26,代码来源:fileutil_windows.go

示例15: init

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")

}
开发者ID:henrylee2cn,项目名称:xcgui,代码行数:28,代码来源:kernel32.go


注:本文中的syscall.MustLoadDLL函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。