public static int HandleToProcessId(SafeMemoryHandle processHandle)
{
// Check if the handle is valid
ValidateAsArgument(processHandle, "processHandle");
// Find the process id
var ret = NativeMethods.GetProcessId(processHandle);
// If the process id is valid
if (ret != 0)
return ret;
// Else the function failed, throws an exception
throw new Win32Exception("Couldn't find the process id of the specified handle.");
}