mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -04:00
windows: add GetProcessId function
ref: https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-getprocessid Document does not say anything about return value, but when I use 0 for HANDLE, GetProcessId returns 0 with ERROR_INVALID_HANDLE from GetLastError(). Change-Id: Ib6782ccd5a4917e93ddbcf18c533921b12c67e3b Reviewed-on: https://go-review.googlesource.com/c/sys/+/180924 Reviewed-by: Marc-Antoine Ruel <maruel@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Alex Brainman
parent
93c9922d18
commit
914ada52e9
@@ -266,6 +266,7 @@ func NewCallbackCDecl(fn interface{}) uintptr {
|
||||
//sys GetPriorityClass(process Handle) (ret uint32, err error) = kernel32.GetPriorityClass
|
||||
//sys SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobObjectInformation uintptr, JobObjectInformationLength uint32) (ret int, err error)
|
||||
//sys GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err error)
|
||||
//sys GetProcessId(process Handle) (id uint32, err error)
|
||||
|
||||
// Volume Management Functions
|
||||
//sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW
|
||||
|
||||
@@ -205,6 +205,7 @@ var (
|
||||
procGetPriorityClass = modkernel32.NewProc("GetPriorityClass")
|
||||
procSetInformationJobObject = modkernel32.NewProc("SetInformationJobObject")
|
||||
procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent")
|
||||
procGetProcessId = modkernel32.NewProc("GetProcessId")
|
||||
procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW")
|
||||
procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW")
|
||||
procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW")
|
||||
@@ -2209,6 +2210,19 @@ func GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err erro
|
||||
return
|
||||
}
|
||||
|
||||
func GetProcessId(process Handle) (id uint32, err error) {
|
||||
r0, _, e1 := syscall.Syscall(procGetProcessId.Addr(), 1, uintptr(process), 0, 0)
|
||||
id = uint32(r0)
|
||||
if id == 0 {
|
||||
if e1 != 0 {
|
||||
err = errnoErr(e1)
|
||||
} else {
|
||||
err = syscall.EINVAL
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) {
|
||||
r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)))
|
||||
if r1 == 0 {
|
||||
|
||||
Reference in New Issue
Block a user