mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-05 16:47:27 -04:00
windows: add module handle functions
These are in internal/syscall/windows, but not here, and they're quite handy to have. Change-Id: I79fe78d3c6bc2c001f994b03ce575287908d2c59 Reviewed-on: https://go-review.googlesource.com/c/sys/+/199518 Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
@@ -77,6 +77,8 @@ var (
|
||||
procLoadLibraryExW = modkernel32.NewProc("LoadLibraryExW")
|
||||
procFreeLibrary = modkernel32.NewProc("FreeLibrary")
|
||||
procGetProcAddress = modkernel32.NewProc("GetProcAddress")
|
||||
procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
|
||||
procGetModuleHandleExW = modkernel32.NewProc("GetModuleHandleExW")
|
||||
procGetVersion = modkernel32.NewProc("GetVersion")
|
||||
procFormatMessageW = modkernel32.NewProc("FormatMessageW")
|
||||
procExitProcess = modkernel32.NewProc("ExitProcess")
|
||||
@@ -683,6 +685,31 @@ func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func GetModuleFileName(module Handle, filename *uint16, size uint32) (n uint32, err error) {
|
||||
r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(filename)), uintptr(size))
|
||||
n = uint32(r0)
|
||||
if n == 0 {
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
} else {
|
||||
err = syscall.EINVAL
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetModuleHandleEx(flags uint32, moduleName *uint16, module *Handle) (err error) {
|
||||
r1, _, e1 := syscall.Syscall(procGetModuleHandleExW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(moduleName)), uintptr(unsafe.Pointer(module)))
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
} else {
|
||||
err = syscall.EINVAL
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetVersion() (ver uint32, err error) {
|
||||
r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
|
||||
ver = uint32(r0)
|
||||
|
||||
Reference in New Issue
Block a user