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


Golang syscall.LoadDLL函数代码示例

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


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

示例1: initCache

func initCache() {
	if iphlpapi, err := syscall.LoadDLL("Iphlpapi.dll"); err == nil {
		if p, err := iphlpapi.FindProc("NotifyAddrChange"); err == nil {
			notifyAddrChange = p
		}
	}

	if advapi32, err := syscall.LoadDLL("Advapi32.dll"); err == nil {
		if p, err := advapi32.FindProc("RegNotifyChangeKeyValue"); err == nil {
			regNotifyChangeKeyValue = p
		}
	}

	cacheLock.Lock()
	defer cacheLock.Unlock()

	notifyCh = make(chan error)

	if regNotifyChangeKeyValue != nil && notifyAddrChange != nil {
		useLookup = true
		go notifyIpChange(notifyCh)
		go notifyRegChange(registry.CURRENT_USER, PathInternetSettings, notifyCh)
	}

	cache = make(map[string]*url.URL)

	go func() {
		for _ = range notifyCh {
			invalidateCache()
		}
	}()
}
开发者ID:koofr,项目名称:autoproxy,代码行数:32,代码来源:autoproxy_windows.go

示例2: getAllWindowsLocaleFrom

func getAllWindowsLocaleFrom(sysCall string) (string, error) {
	dll, err := syscall.LoadDLL("kernel32")
	if err != nil {
		return "", errors.New("Could not find kernel32 dll")
	}

	proc, err := dll.FindProc(sysCall)
	if err != nil {
		return "", err
	}

	locale, _, dllError := proc.Call()
	if locale == 0 {
		return "", errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
	}
	proc, err = dll.FindProc("GetLocaleInfoW")
	if err != nil {
		return "", err
	}
	langBuf := make([]uint16, LOCALE_SISO_NAME_MAX_LENGTH)
	r, _, dllError := proc.Call(locale, uintptr(LOCALE_SISO639LANGNAME), uintptr(unsafe.Pointer(&langBuf[0])), uintptr(LOCALE_SISO_NAME_MAX_LENGTH))
	if r == 0 {
		err = errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
		return "", err
	}
	countryBuf := make([]uint16, LOCALE_SISO_NAME_MAX_LENGTH)
	r, _, dllError = proc.Call(locale, uintptr(LOCALE_SISO3166CTRYNAME), uintptr(unsafe.Pointer(&countryBuf[0])), uintptr(LOCALE_SISO_NAME_MAX_LENGTH))
	if r == 0 {
		err = errors.New(COULD_NOT_DETECT_PACKAGE_ERROR_MESSAGE + ":\n" + dllError.Error())
		return "", err
	}
	return syscall.UTF16ToString(langBuf) + "-" + syscall.UTF16ToString(countryBuf), nil
}
开发者ID:Christeefym,项目名称:lantern,代码行数:33,代码来源:jibber_jabber_windows.go

示例3: terminateProc

func terminateProc(proc string) error {
	dll, err := syscall.LoadDLL("kernel32.dll")
	if err != nil {
		return err
	}
	defer dll.Release()

	pid := procs[proc].cmd.Process.Pid

	f, err := dll.FindProc("SetConsoleCtrlHandler")
	if err != nil {
		return err
	}
	r1, _, err := f.Call(0, 1)
	if r1 == 0 {
		return err
	}
	f, err = dll.FindProc("GenerateConsoleCtrlEvent")
	if err != nil {
		return err
	}
	r1, _, err = f.Call(syscall.CTRL_BREAK_EVENT, uintptr(pid))
	if r1 == 0 {
		return err
	}
	return nil
}
开发者ID:mattn,项目名称:goreman,代码行数:27,代码来源:proc_windows.go

示例4: SaferDLLLoading

// SaferDLLLoading sets DLL load path to be safer.
func SaferDLLLoading() error {
	kernel32, err := syscall.LoadDLL("kernel32.dll")
	if err != nil {
		return err
	}

	procSetDllDirectoryW, err := kernel32.FindProc("SetDllDirectoryW")
	if err != nil {
		return err
	}
	var zero uint16
	r1, _, e1 := syscall.Syscall(procSetDllDirectoryW.Addr(), 1,
		uintptr(unsafe.Pointer(&zero)), 0, 0)

	procSetDefaultDllDirectories, err := kernel32.FindProc("SetDefaultDllDirectories")
	if err == nil && procSetDefaultDllDirectories.Addr() != 0 {
		r1, _, e1 = syscall.Syscall(procSetDefaultDllDirectories.Addr(), 1,
			loadLibrarySearchSystem32, 0, 0)
		if r1 == 0 {
			return e1
		}
	} else {
		return errors.New("SetDefaultDllDirectories not found - please install KB2533623 for safer DLL loading")
	}

	return nil
}
开发者ID:qbit,项目名称:client,代码行数:28,代码来源:saferdllloading_windows.go

示例5: LoadDLL

// LoadDLL loads a DLL file into memory. It panics if the file is not found.
func LoadDLL(name string) DLL {
	lib, err := syscall.LoadDLL(name)
	if err != nil {
		panic(err)
	}
	return DLL{lib}
}
开发者ID:tianlin,项目名称:com-and-go,代码行数:8,代码来源:func.go

示例6: GetDLL

func GetDLL(t *testing.T, name string) *DLL {
	d, e := syscall.LoadDLL(name)
	if e != nil {
		t.Fatal(e)
	}
	return &DLL{DLL: d, t: t}
}
开发者ID:wheelcomplex,项目名称:go-1,代码行数:7,代码来源:syscall_windows_test.go

示例7: GetFilesystemRoots

func GetFilesystemRoots() ([]string, error) {
	kernel32, err := syscall.LoadDLL("kernel32.dll")
	if err != nil {
		return nil, err
	}
	getLogicalDriveStringsHandle, err := kernel32.FindProc("GetLogicalDriveStringsA")
	if err != nil {
		return nil, err
	}

	buffer := [1024]byte{}
	bufferSize := uint32(len(buffer))

	hr, _, _ := getLogicalDriveStringsHandle.Call(uintptr(unsafe.Pointer(&bufferSize)), uintptr(unsafe.Pointer(&buffer)))
	if hr == 0 {
		return nil, fmt.Errorf("Syscall failed")
	}

	var drives []string
	parts := bytes.Split(buffer[:], []byte{0})
	for _, part := range parts {
		if len(part) == 0 {
			break
		}
		drives = append(drives, string(part))
	}

	return drives, nil
}
开发者ID:letiemble,项目名称:syncthing,代码行数:29,代码来源:fsroots_windows.go

示例8: getWindowsLocale

func getWindowsLocale() (locale string, err error) {
	dll, err := syscall.LoadDLL("kernel32")
	if err != nil {
		return "", errors.New("Could not find kernel32 dll")
	}

	proc, err := dll.FindProc("GetVersion")
	if err != nil {
		return "", err
	}

	v, _, _ := proc.Call()
	windowsVersion := byte(v)
	isVistaOrGreater := (windowsVersion >= 6)

	if isVistaOrGreater {
		locale, err = getWindowsLocaleFrom("GetUserDefaultLocaleName")
		if err != nil {
			locale, err = getWindowsLocaleFrom("GetSystemDefaultLocaleName")
		}
	} else if !isVistaOrGreater {
		locale, err = getAllWindowsLocaleFrom("GetUserDefaultLCID")
		if err != nil {
			locale, err = getAllWindowsLocaleFrom("GetSystemDefaultLCID")
		}
	} else {
		panic(v)
	}
	return
}
开发者ID:ChrisOHu,项目名称:platform,代码行数:30,代码来源:jibber_jabber_windows.go

示例9: loadDLL

func loadDLL(name string) *cutoDLL {
	dll, err := syscall.LoadDLL(name)
	if err != nil {
		panic(err)
	}
	cutoDll := new(cutoDLL)
	cutoDll.dll = dll
	return cutoDll
}
开发者ID:unirita,项目名称:remexec,代码行数:9,代码来源:winrm_windows.go

示例10: ColorEdit

/*
   控制台彩色输出,1深蓝,2深绿,3深青,10绿色,11青色,12红色
   The console color output,1 deep blue,2 deep green,3 deep cyan,10 green,11 cyan,12 red
*/
func ColorEdit(i int) {
	kernel32, _ := syscall.LoadDLL("kernel32.dll") //调用dll,call dll
	defer kernel32.Release()                       //延迟释放,delay release
	/*
		找到dll中的方法,并返回此方法
		find the method in the dll and return the method
	*/
	proc, _ := kernel32.FindProc("SetConsoleTextAttribute")
	proc.Call(uintptr(syscall.Stdout), uintptr(i)) //执行此方法,carry out the method
}
开发者ID:john049,项目名称:chatroom,代码行数:14,代码来源:server.go

示例11: LoadDLL

// LoadDLL loads specified DLL using syscall.LoadDLL (i.e. LoadLibraryW)
// and returns an error if any occurred during the syscall.LoadDLL
// Calling LoadDLL twice or on already loaded DLL has no effect.
func (w *W32s) LoadDLL(name string) error {
	if _, ok := w.dlls[name]; !ok {
		dll, err := syscall.LoadDLL(name)
		if err != nil {
			return err
		}
		w.dlls[name] = newDll(dll, w.encoding)
	}
	return nil
}
开发者ID:RIscRIpt,项目名称:w32s,代码行数:13,代码来源:w32s.go

示例12: load_qtdrv_proc

func load_qtdrv_proc() (uintptr, error) {
	lib, err := syscall.LoadDLL("qtdrv.ui.dll")
	if err != nil {
		return 0, err
	}
	proc, err := lib.FindProc("qtdrv")
	if err != nil {
		return 0, err
	}
	return proc.Addr(), nil
}
开发者ID:gooops,项目名称:goqt,代码行数:11,代码来源:cdrv_windows.go

示例13: init

func init() {
	kernel32 := syscall.NewLazyDLL("kernel32.dll")

	procGetStdHandle = kernel32.NewProc("GetStdHandle")

	hStdout, _, _ = procGetStdHandle.Call(uintptr(std_output_handle))

	initScreenInfo = getConsoleScreenBufferInfo(hStdout)

	syscall.LoadDLL("")
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:11,代码来源:ct_win.go

示例14: sendCtrlBreak

func sendCtrlBreak(pid int) {
	d, e := syscall.LoadDLL("kernel32.dll")
	if e != nil {
		return
	}
	p, e := d.FindProc("GenerateConsoleCtrlEvent")
	if e != nil {
		return
	}
	p.Call(syscall.CTRL_BREAK_EVENT, uintptr(pid))
}
开发者ID:Joffcom,项目名称:silver,代码行数:11,代码来源:terminate_windows.go

示例15: loadProc

func loadProc() *syscall.Proc {
	dll, err := syscall.LoadDLL("kernel32.dll")
	if err != nil {
		panic(err)
	}
	proc, err := dll.FindProc("GetModuleFileNameW")
	if err != nil {
		panic(err)
	}
	return proc
}
开发者ID:unirita,项目名称:gocutoweb,代码行数:11,代码来源:root_windows.go


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