In this small program, why does GetCurrentProcess() return -1?
int _tmain(int argc, _TCHAR* argv[]) { HANDLE h = GetCurrentProcess(); // ret -1 printf("0x%x\n",(DWORD)h); return 0; } What's wrong?
In Kernel32.GetCurrentProcess I see this:
OR EAX,FFFFFFFF ; EAX - ? RETN
That is correct, see this API reference for GetCurrentProcess.
The
GetCurrentProcessfunction retrieves a pseudo-handle for the current process, which is currently defined as(HANDLE)-1. However, because you should not assume that the value will never change, theGetCurrentProcessfunction is provided as an alternative to hard-coding the constant into your code.
-1 is the pseudo-handle that represents the current process. It's normal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With