本文整理汇总了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()
}
}()
}
示例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
}
示例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
}
示例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
}
示例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}
}
示例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}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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("")
}
示例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))
}
示例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
}