-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpsapi.go
More file actions
33 lines (29 loc) · 670 Bytes
/
Copy pathpsapi.go
File metadata and controls
33 lines (29 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package win
import (
"golang.org/x/sys/windows"
"syscall"
"unsafe"
)
var (
libpsapi *windows.LazyDLL
getModuleFileNameExW *windows.LazyProc
)
func init() {
libpsapi = windows.NewLazySystemDLL("Psapi.dll")
getModuleFileNameExW = libpsapi.NewProc("GetModuleFileNameExW")
}
func GetModuleFileNameEx(process, module HANDLE) (string, bool) {
size := windows.MAX_LONG_PATH
name := make([]uint16, size)
ret, _, _ := syscall.Syscall6(getModuleFileNameExW.Addr(), 4,
uintptr(process),
uintptr(module),
uintptr(unsafe.Pointer(&name[0])),
uintptr(size),
0,
0)
if ret > 0 {
name = name[:ret]
}
return UTF16PtrToString(&name[0]), ret > 0
}