What is the difference between Getcurrentprocess and Getcurrentprocessid?

Asked

Viewed 650 times

6

What’s the difference between the call GetCurrentProcess and the MainHandle defined below:

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

In my application only the GetCurrentProcess have the expected effect, but I doubted the difference between them.

1 answer

6


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

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

Unless Delphi has two forms OpenProcess() original Microsoft API is waiting for the ID, so only the second should work. And even if you can use the handler beyond the ID or they end up getting confused, both should work.

It may be that the ID is not coming correctly for some reason that I don’t know, maybe it only works in some contexts. Have you tried the GetWindowThreadProcessId()

  • Understood the difference friend, thank you very much link clarification

Browser other questions tagged

You are not signed in. Login or sign up in order to post.