如何比较两个变量的HANDLE类型 [英] How to Compare Two variable of HANDLE type

查看:526
本文介绍了如何比较两个变量的HANDLE类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有变量的HANDLE类型。
第一个变量是具有PROCESS_QUERY_INFORMATION访问权限的进程HANDLE(名称为hProcess)。
第二个变量是一个进程HANDLE(名称为hwndProcess),我通过OpenProcess函数打开并具有PROCESS_QUERY_INFORMATION访问权限。我确定这两个过程是一个。
但是当我比较如下return false;
if(hProcess == hwndProcess){do something}
我应该怎么办?

i have to variable of HANDLE type . first variable is a process HANDLE (with name hProcess) that have'nt PROCESS_QUERY_INFORMATION access right. second variable is a process HANDLE (with name hwndProcess) too that i opened via OpenProcess function and have PROCESS_QUERY_INFORMATION access right. i sure both process is a one. but when i compare as below return false; if (hProcess==hwndProcess) {do something} how should i do?

推荐答案

不是一个显式的方法来检查两个句柄是否指向相同的进程。唯一的方法是查询过程信息,并检查,例如。使用 GetProcessId 在每个句柄上检查进程ID。

There is not an explicit way to check whether two handles refer to the same process. The only way would be to query the process information and check that, e.g. using GetProcessId on each handle to check the process IDs.

如果您没有必要的访问权限调用所需的查询函数,然后你可以尝试调用 DuplicateHandle 获得一个具有更多访问权限的新句柄。然而,如果这失败,那么你无法知道句柄是否是相同的过程。

If you don't have the necessary access rights to call the desired query functions then you can try calling DuplicateHandle to get a new handle with more access rights. However, if this fails then you have no way of telling whether the handles are to the same process or not.

这篇关于如何比较两个变量的HANDLE类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆