TerminateProcess pinvoke

  • Thread starter Thread starter Jose
  • Start date Start date
J

Jose

Hello,

I'm trying to grab the process id based on the window's Hwnd. I can
get the process id correctly, but I can't figure out how to pass that
into TerminateProcess. Assuming the call to GetWindowThreadProcessId()
gets a valid procID, how can I use that to call TerminateProcess? Is
my pinvoke wrong?

[DllImport("coredll")] public static extern uint
GetWindowThreadProcessId(IntPtr hwnd, out uint lpdwProcessId);
[DllImport("coredll")] public static extern int TerminateProcess(IntPtr
procID, uint uExitCode);
uint theProc = 0;
GetWindowThreadProcessId(hwnd, out procID);
 
TerminateProcess takes a hProcess (handle to a process) you can use
OpenProcess to return the handle from the PID.

Peter
 
Back
Top