本文整理汇总了Golang中syscall.GetProcAddress函数的典型用法代码示例。如果您正苦于以下问题:Golang GetProcAddress函数的具体用法?Golang GetProcAddress怎么用?Golang GetProcAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetProcAddress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: init
func init() {
var nStdHandle = -11
kernel32, _ = syscall.LoadLibrary("Kernel32.dll")
GetStdHandle, _ = syscall.GetProcAddress(syscall.Handle(kernel32), "GetStdHandle")
SetConsoleTextAttribute, _ = syscall.GetProcAddress(syscall.Handle(kernel32), "SetConsoleTextAttribute")
// ReadConsoleOutputAttribute, _ := syscall.GetProcAddress(syscall.Handle(kernel32), "ReadConsoleOutputAttribute")
GetConsoleScreenBufferInfo, _ = syscall.GetProcAddress(syscall.Handle(kernel32), "GetConsoleScreenBufferInfo")
hnd, _, _ = syscall.Syscall(uintptr(GetStdHandle), 1, uintptr(nStdHandle), 0, 0)
}
示例3: Initdriver
func (jst *TCFinger) Initdriver(pin *driverlayer.DriverArg) {
var err error
jst.stdll, err = syscall.LoadLibrary("third_party/teso/TesoLive.dll")
if err != nil {
panic("LoadLibrary " + err.Error())
}
jst.getRegisterImage, err = syscall.GetProcAddress(jst.stdll, "FPIGetTemplate")
jst.getValidteImage, err = syscall.GetProcAddress(jst.stdll, "FPIGetFeature")
jst.matchtz, err = syscall.GetProcAddress(jst.stdll, "FPIMatch")
}
示例4: init
func init() {
var err error
if msvcrt, err = syscall.LoadLibrary("msvcrt.dll"); err != nil {
abort("LoadLibrary", err)
}
if setlocale, err = syscall.GetProcAddress(msvcrt, "setlocale"); err != nil {
abort("GetProcAddress", err)
}
if wcstombs, err = syscall.GetProcAddress(msvcrt, "wcstombs"); err != nil {
abort("GetProcAddress", err)
}
if mbstowcs, err = syscall.GetProcAddress(msvcrt, "mbstowcs"); err != nil {
abort("GetProcAddress", err)
}
}
示例5: 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
}
示例6: getProcAddr
func getProcAddr(lib syscall.Handle, name string) uintptr {
addr, err := syscall.GetProcAddress(lib, name)
if err != nil {
panic(name + " " + err.Error())
}
return addr
}
示例7: InitalFunctions
func (p *Dll) InitalFunctions(funcNames ...string) error {
if funcNames == nil {
return nil
}
if !p.IsDllLoaded() {
return errors.New("dll should loaded befor inital functions")
}
if p.funcProcs == nil {
p.funcProcs = make(map[string]uintptr)
}
for _, funcName := range funcNames {
funcName = strings.TrimSpace(funcName)
if funcName == "" {
return errors.New("function name could not be empty")
}
if proc, e := syscall.GetProcAddress(p.dllHandler, funcName); e != nil {
return e
} else {
p.funcProcs[funcName] = proc
}
}
return nil
}
示例8: 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
}
示例9: getSysProcAddr
func getSysProcAddr(m uint32, pname string) uintptr {
p, e := syscall.GetProcAddress(m, pname)
if e != 0 {
panic("GetProcAddress failed on " + pname)
}
return uintptr(p)
}
示例10: 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())
}
}
示例11: 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")
}
示例12: getProcAddr
func getProcAddr(lib syscall.Handle, name string) uintptr {
addr, err := syscall.GetProcAddress(lib, name)
if err != 0 {
panic(name + " " + syscall.Errstr(err))
}
return addr
}
示例13: 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
}
示例14: getSysProcAddr
func getSysProcAddr(m uint32, pname string) uintptr {
p, e := syscall.GetProcAddress(m, pname)
if e != 0 {
abortf("GetProcAddress(%s) failed with err=%d.\n", pname, e)
}
return uintptr(p)
}
示例15: 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)
}
}