I am trying to terminate another application (MFC), by getting the handle, opening a process and terminating it. I have tried sending messages to the window but it dosnt work (WM_CLOSE/WM_DESTROY).
// error checking removed
DWORD dwPid, error;
// process closed
hWndNews = FindWindow(NULL, "4.32 - Build: 4969");
dwPid = GetWindowThreadProcessId(hWndNews, NULL);
hNews = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);
The handle is correct, although the dwPid contains 740 and spy++ says its 000007D0.
Anyone know how i can fix this/close the program?
Are you sure the thread you are running has PROCESS_TERMINATE rights? What does TerminateProcess return? If false, what does GetLastError return?
Make sure the handle to the process is valid. The same applies to all other handles.