如何获得当前的处理手柄? [英] how to get current Process HANDLE?

查看:64
本文介绍了如何获得当前的处理手柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能获得当前的流程处理?



函数GetCurrentProcess返回

how can i get my current process handle?

the function GetCurrentProcess return

The return value is a pseudo handle to the current process.





即它总是返回伪句柄是一个特殊常量,当前(HANDLE)-1 => 0xFFFFFFFF( MSDN)



使用OpenProcess代码:





that is it allways return "pseudo handle is a special constant, currently (HANDLE)-1 => 0xFFFFFFFF" (MSDN)

using the code with OpenProcess:

DWORD pid = GetCurrentProcessId();
HANDLE hProcess2 = OpenProcess(0, FALSE, pid);





返回NULL



所以我可以得到真正的句柄?:confused:



当我用的时候





return NULL

so i can get the real handle?:confused:

when i used

HANDLE hProcess2 = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);



它看起来有效,但我怎么能确定当我尝试使用VirtualLock中的句柄时我总是得到错误。


it looks to work but how can i be sure becuase when i try to use the handle in the VirtualLock i allways get error.

推荐答案

VirtualLock返回什么错误?除非它像无效的进程句柄之类的东西,否则可能会出现其他问题,比如你试图锁定太多的地址空间。



说实话,VirtualLock是可能是Win32中更无用的函数之一。它只是说我可能,如果我感觉很慷慨,保证不会使这个页面无效,这并不是对功能实用程序的惊人认可。即使你把你的页面锁定,也要记得对你的应用进行分析,看看它是否真的会对它的性能产生任何影响。



干杯,



Ash
What error does VirtualLock return? Unless it's something like "invalid process handle" then it could be something else going wrong like you're trying to lock too much address space.

To be honest VirtualLock is probably one of the more useless functions in the Win32. All it says is "I may, if I'm feeling generous, guarentee not to invalidate this page" which isn't stunning endorsement of the functions utility. And even if you get your pages to lock remember to profile your app to see if it actually makes any sort of difference to it's performance.

Cheers,

Ash


为什么不尝试使用真正的句柄而不是GetCurrentProcess返回的伪句柄。使用DuplicateHandle函数
Why dont you try using a real handle rather than the pseudo handle returned by the GetCurrentProcess. Create a handle using the function DuplicateHandle


这篇关于如何获得当前的处理手柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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