TerminateProcess pinvoke

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);
 
P

Peter Foot [MVP]

TerminateProcess takes a hProcess (handle to a process) you can use
OpenProcess to return the handle from the PID.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top