Skip to content

Commit

Permalink
Add GetCurrentProcess and change GetProcessTimes
Browse files Browse the repository at this point in the history
GetProcessTimes now returns 4 FILETIMEs instead of taking pointers to
them as arguments. This is more Go-like.
  • Loading branch information
lars committed Feb 22, 2021
1 parent 5ce3d47 commit 8e6db4f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ var (
systemTimeToFileTime = kernel32.NewProc("SystemTimeToFileTime")
fileTimeToSystemTime = kernel32.NewProc("FileTimeToSystemTime")
copyMemory = kernel32.NewProc("RtlCopyMemory")
getCurrentProcess = kernel32.NewProc("GetCurrentProcess")
getCurrentProcessId = kernel32.NewProc("GetCurrentProcessId")
getVersion = kernel32.NewProc("GetVersion")
setEnvironmentVariable = kernel32.NewProc("SetEnvironmentVariableW")
Expand Down Expand Up @@ -3754,15 +3755,16 @@ func GetSystemTimes(lpIdleTime, lpKernelTime, lpUserTime *FILETIME) bool {
return ret != 0
}

func GetProcessTimes(hProcess HANDLE, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime *FILETIME) bool {
func GetProcessTimes(hProcess HANDLE) (creationTime, exitTime, kernelTime, userTime FILETIME, ok bool) {
ret, _, _ := getProcessTimes.Call(
uintptr(hProcess),
uintptr(unsafe.Pointer(lpCreationTime)),
uintptr(unsafe.Pointer(lpExitTime)),
uintptr(unsafe.Pointer(lpKernelTime)),
uintptr(unsafe.Pointer(lpUserTime)),
uintptr(unsafe.Pointer(&creationTime)),
uintptr(unsafe.Pointer(&exitTime)),
uintptr(unsafe.Pointer(&kernelTime)),
uintptr(unsafe.Pointer(&userTime)),
)
return ret != 0
ok = ret != 0
return
}

func GetConsoleScreenBufferInfo(hConsoleOutput HANDLE) *CONSOLE_SCREEN_BUFFER_INFO {
Expand Down Expand Up @@ -3843,6 +3845,11 @@ func CopyMemory(dest, source unsafe.Pointer, sizeInBytes int) {
)
}

func GetCurrentProcess() HANDLE {
id, _, _ := getCurrentProcess.Call()
return HANDLE(id)
}

func GetCurrentProcessId() DWORD {
id, _, _ := getCurrentProcessId.Call()
return DWORD(id)
Expand Down

0 comments on commit 8e6db4f

Please sign in to comment.