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


Golang syscall.LoadLibrary函数代码示例

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


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

示例1: init

func init() {
	// Library
	libgdi32, _ = syscall.LoadLibrary("gdi32.dll")
	libuser32, _ = syscall.LoadLibrary("user32.dll")
	liboleaut32, _ = syscall.LoadLibrary("oleaut32.dll")
	libkernel32, _ = syscall.LoadLibrary("kernel32.dll")

	stretchDIBits, _ = syscall.GetProcAddress(libgdi32, "StretchDIBits")

	getClientRect, _ = syscall.GetProcAddress(libuser32, "GetClientRect")
	defWindowProc, _ = syscall.GetProcAddress(libuser32, "DefWindowProcW")
	loadCursor, _ = syscall.GetProcAddress(libuser32, "LoadCursorW")
	registerClassEx, _ = syscall.GetProcAddress(libuser32, "RegisterClassExW")
	adjustWindowRect, _ = syscall.GetProcAddress(libuser32, "AdjustWindowRect")
	createWindowEx, _ = syscall.GetProcAddress(libuser32, "CreateWindowExW")
	showWindow, _ = syscall.GetProcAddress(libuser32, "ShowWindow")
	getDC, _ = syscall.GetProcAddress(libuser32, "GetDC")
	getMessage, _ = syscall.GetProcAddress(libuser32, "GetMessageW")
	translateMessage, _ = syscall.GetProcAddress(libuser32, "TranslateMessage")
	dispatchMessage, _ = syscall.GetProcAddress(libuser32, "DispatchMessageW")
	invalidateRect, _ = syscall.GetProcAddress(libuser32, "InvalidateRect")
	validateRect, _ = syscall.GetProcAddress(libuser32, "ValidateRect")
	sendMessage, _ = syscall.GetProcAddress(libuser32, "SendMessageW")
	postMessage, _ = syscall.GetProcAddress(libuser32, "PostMessageW")
	destroyWindow, _ = syscall.GetProcAddress(libuser32, "DestroyWindow")

	sysAllocString, _ = syscall.GetProcAddress(liboleaut32, "SysAllocString")

	getLastError, _ = syscall.GetProcAddress(libkernel32, "GetLastError")
}
开发者ID:andyleap,项目名称:tinyfb,代码行数:30,代码来源:w32.go

示例2: XAudio2Create

func XAudio2Create(ppXAudio2 **IXAudio2) (ret int32) {
	libole32, _ := syscall.LoadLibrary("ole32.dll")
	ptrcoInitializeEx, _ = syscall.GetProcAddress(syscall.Handle(libole32), "CoInitializeEx")
	ptrcoCreateInstance, _ = syscall.GetProcAddress(syscall.Handle(libole32), "CoCreateInstance")

	coInitializeEx(nil, 0)

	// XAudio 2.7 GUIDs
	clsid := guid{0x5a508685, 0xa254, 0x4fba, [8]byte{0x9b, 0x82, 0x9a, 0x24, 0xb0, 0x03, 0x06, 0xaf}}
	iid := guid{0x8bcf1f58, 0x9fe7, 0x4583, [8]byte{0x8a, 0xc6, 0xe2, 0xad, 0xc4, 0x65, 0xc8, 0xbb}}
	var com unsafe.Pointer
	ret = coCreateInstance(&clsid, nil, 1, &iid, &com)
	if ret < 0 {
		return
	}

	pXAudio2 := (*IXAudio2)(com)
	ret = pXAudio2.Initialize(0, 0xffffffff)
	if ret < 0 {
		pXAudio2.Release()
		return
	}

	*ppXAudio2 = pXAudio2
	return
}
开发者ID:ccherng,项目名称:go-xaudio2,代码行数:26,代码来源:xaudio2.go

示例3: testFail

func testFail() {
	h, err := syscall.LoadLibrary("msvcrt")
	if err != nil {
		fmt.Println(err)
		return
	}

	defer syscall.FreeLibrary(h)

	proc, err := syscall.GetProcAddress(h, "memcpy")
	if err != nil {
		fmt.Println(err)
		return
	}

	// dst := unsafe.Pointer(uintptr(1))
	// src := unsafe.Pointer(uintptr(2))
	// count := unsafe.Pointer(uintptr(4))
	dst := uintptr(1)
	src := uintptr(2)
	count := uintptr(3)

	fmt.Println("test memcpy error in go...")
	r, _, _ := syscall.Syscall(uintptr(proc), 3, dst, src, count)

	fmt.Println(r)
	fmt.Println("should not run here")

}
开发者ID:yuanlv,项目名称:learning-in-go,代码行数:29,代码来源:go_call_c.go

示例4: DiskSpace

// Returns total and free bytes available in a directory.
// It returns free space available to the user (including quota limitations),
// so it can be lower than the free space of the disk.
func DiskSpace(path string) (total, free int64, err error) {
	kernel32, err := syscall.LoadLibrary("Kernel32.dll")
	if err != nil {
		return
	}
	defer syscall.FreeLibrary(kernel32)
	GetDiskFreeSpaceEx, err := syscall.GetProcAddress(
		syscall.Handle(kernel32), "GetDiskFreeSpaceExW")
	if err != nil {
		return
	}
	lpFreeBytesAvailable := int64(0)
	lpTotalNumberOfBytes := int64(0)
	lpTotalNumberOfFreeBytes := int64(0)
	r1, _, e1 := syscall.Syscall6(uintptr(GetDiskFreeSpaceEx), 4,
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)), 0, 0)
	if r1 == 0 {
		if e1 != 0 {
			err = error(e1)
		} else {
			err = syscall.EINVAL
		}
		return
	}
	total = lpTotalNumberOfBytes
	free = lpFreeBytesAvailable
	return
}
开发者ID:YijinLiu,项目名称:usongs,代码行数:34,代码来源:disk_space_windows.go

示例5: freeDiskSpaceBytes2

// *************************************************************************
// We can probably delete this, it is an alternative version in case we have
// problems with simpler version above
// *************************************************************************
func freeDiskSpaceBytes2(dir string) (uint64, error) {
	kernel32, err := syscall.LoadLibrary("Kernel32.dll")
	if err != nil {
		log.Panic(err)
	}
	defer syscall.FreeLibrary(kernel32)
	GetDiskFreeSpaceEx, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetDiskFreeSpaceExW")
	if err != nil {
		return 0, err
	}
	lpFreeBytesAvailable := int64(0)
	lpTotalNumberOfBytes := int64(0)
	lpTotalNumberOfFreeBytes := int64(0)
	r, a, b := syscall.Syscall6(
		uintptr(GetDiskFreeSpaceEx),
		4,
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("C:"))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)),
		0,
		0,
	)
	log.Print("Disk space:", r, a, b, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes)
	return uint64(lpFreeBytesAvailable), nil
}
开发者ID:petemoore,项目名称:generic-worker,代码行数:30,代码来源:diskspace_windows.go

示例6: main

func main() {
	//首先,准备输入参数, GetDiskFreeSpaceEx需要4个参数, 可查MSDN
	// dir := "C:"
	lpFreeBytesAvailable := int64(0) //注意类型需要跟API的类型相符
	lpTotalNumberOfBytes := int64(0)
	lpTotalNumberOfFreeBytes := int64(0)

	//获取方法的引用
	kernel32, err := syscall.LoadLibrary("Kernel32.dll") // 严格来说需要加上 defer syscall.FreeLibrary(kernel32)
	if err != nil {
		log.Println(err.Error())
	}
	defer syscall.FreeLibrary(kernel32)
	GetDiskFreeSpaceEx, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetDiskFreeSpaceExW")

	//执行之. 因为有4个参数,故取Syscall6才能放得下. 最后2个参数,自然就是0了
	r, _, errno := syscall.Syscall6(uintptr(GetDiskFreeSpaceEx), 4,
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("C:"))),
		uintptr(unsafe.Pointer(&lpFreeBytesAvailable)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfBytes)),
		uintptr(unsafe.Pointer(&lpTotalNumberOfFreeBytes)), 0, 0)

	if errno != 0 {
		log.Println(errno)
	}
	// 注意, errno并非error接口的, 不可能是nil
	// 而且,根据MSDN的说明,返回值为0就fail, 不为0就是成功
	if r != 0 {
		log.Printf("Free %dmb", lpTotalNumberOfFreeBytes/1024/1024)
	}
}
开发者ID:bonly,项目名称:exercise,代码行数:31,代码来源:20120329_win_free_disk.go

示例7: Initdriver

func (jst *IDCGeneral) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.termdll, err = syscall.LoadLibrary("third_party/general/sdtapi.dll")
	if err != nil {
		panic("load library error:" + err.Error())
	}

	f := func(n string, res *uintptr) bool {
		*res, err = syscall.GetProcAddress(jst.termdll, n)
		if err != nil {
			syscall.FreeLibrary(jst.termdll)
			panic("load proc " + n + " error:" + err.Error())
		}
		return true
	}

	//获得dll的各种handle
	if f("SDT_OpenPort", &jst.initcomm) &&
		f("SDT_ClosePort", &jst.closecomm) &&
		f("SDT_StartFindIDCard", &jst.findcard) &&
		f("SDT_SelectIDCard", &jst.selectcard) &&
		f("SDT_ReadBaseMsg", &jst.readbasemsg) {
	} else {
		utils.Error("Init shensi Driver error...%s", err.Error())
	}

}
开发者ID:kity-xu,项目名称:xuxiaodong,代码行数:27,代码来源:idcgeneral.go

示例8: loadDll

func loadDll(fname string) uint32 {
	h, e := syscall.LoadLibrary(fname)
	if e != 0 {
		abortf("LoadLibrary(%s) failed with err=%d.\n", fname, e)
	}
	return h
}
开发者ID:radhermit,项目名称:gcc,代码行数:7,代码来源:winapi.go

示例9: Rename

func Rename(src, dst string) error {
	kernel32, err := syscall.LoadLibrary("kernel32.dll")
	if err != nil {
		return err
	}
	defer syscall.FreeLibrary(kernel32)
	moveFileExUnicode, err := syscall.GetProcAddress(kernel32, "MoveFileExW")
	if err != nil {
		return err
	}

	srcString, err := syscall.UTF16PtrFromString(src)
	if err != nil {
		return err
	}

	dstString, err := syscall.UTF16PtrFromString(dst)
	if err != nil {
		return err
	}

	srcPtr := uintptr(unsafe.Pointer(srcString))
	dstPtr := uintptr(unsafe.Pointer(dstString))

	MOVEFILE_REPLACE_EXISTING := 0x1
	flag := uintptr(MOVEFILE_REPLACE_EXISTING)

	_, _, callErr := syscall.Syscall(uintptr(moveFileExUnicode), 3, srcPtr, dstPtr, flag)
	if callErr != 0 {
		return callErr
	}

	return nil
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:34,代码来源:rename_windows.go

示例10: loadDll

func loadDll(fname string) uint32 {
	h, e := syscall.LoadLibrary(fname)
	if e != 0 {
		panic("LoadLibrary failed")
	}
	return h
}
开发者ID:sbinet,项目名称:fineline,代码行数:7,代码来源:windows.go

示例11: Initdriver

func (jst *ZZFinger) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.stdll, err = syscall.LoadLibrary("third_party/zhongzheng/FingerDLL.dll")
	if err != nil {
		panic("LoadLibrary " + err.Error())
	}
	jst.read, err = syscall.GetProcAddress(jst.stdll, "drive")
}
开发者ID:kity-xu,项目名称:xuxiaodong,代码行数:8,代码来源:zzfinger.go

示例12: LoadLib

func LoadLib(name string) uintptr {
	lib, err := syscall.LoadLibrary(name)
	if err != nil {
		panic(fmt.Sprintf("syscall.LoadLibrary('%s') failed: %s",
			name, err.Error()))
	}
	return uintptr(lib)
}
开发者ID:bsiegert,项目名称:w32,代码行数:8,代码来源:utils.go

示例13: MustLoadLibrary

func MustLoadLibrary(name string) uint32 {
	lib, errno := syscall.LoadLibrary(name)
	if errno != 0 {
		panic(fmt.Sprintf(`syscall.LoadLibrary("%s") failed: %s`, name, syscall.Errstr(errno)))
	}

	return lib
}
开发者ID:lalitjsraks,项目名称:walk,代码行数:8,代码来源:winapi.go

示例14: LoadLibrary

func (p *Dll) LoadLibrary(fileName string) error {
	if handler, e := syscall.LoadLibrary(fileName); e != nil {
		return e
	} else {
		p.dllHandler = handler
	}
	return nil
}
开发者ID:easykoo,项目名称:dll_caller,代码行数:8,代码来源:dll_caller_windows.go

示例15: MustLoadLibrary

func MustLoadLibrary(name string) uintptr {
	lib, err := syscall.LoadLibrary(name)
	if err != nil {
		panic(err)
	}

	return uintptr(lib)
}
开发者ID:dustywilson,项目名称:go-winapi,代码行数:8,代码来源:winapi.go


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