Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does GetCurrentProcess return -1?

Tags:

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 
like image 609
Kmd Avatar asked Apr 28 '11 11:04

Kmd


2 Answers

That is correct, see this API reference for GetCurrentProcess.

The GetCurrentProcess function 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, the GetCurrentProcess function is provided as an alternative to hard-coding the constant into your code.

like image 119
Skizz Avatar answered Oct 11 '22 12:10

Skizz


-1 is the pseudo-handle that represents the current process. It's normal.

like image 36
user703016 Avatar answered Oct 11 '22 12:10

user703016