What is the difference between GetCurrentProcess and GetCurrentProcessID?

5

What is the difference between calling GetCurrentProcess and MainHandle defined below:

var
  MainHandle: THandle;
begin
MainHandle := OpenProcess(PROCESS_ALL_ACCESS, false, GetCurrentProcessID);
end;

In my application only GetCurrentProcess has the expected effect, but I was not sure what the difference was between them.

    
asked by anonymous 05.01.2015 / 00:19

1 answer

5

As the name says GetCurrentProcess get the process itself, ie a manipulator for the process. You will use this handler to perform actions or get process information.

And also as the name says GetCurrentProcessId get the process identifier, that is, it takes the process number and nothing else. It is just a number that identifies the process but is not the process.

Unless Delphi has two forms, OpenProcess "of the original Microsoft API is expecting the ID, so only the second one should work. And even if you can use the handler beyond the ID or they get confused, both should work.

The ID may not be coming correctly for some reason that I do not know, maybe it only works in some contexts. You've already tried GetWindowThreadProcessId

    
05.01.2015 / 00:36