Hi, so I have two process calling DebugActiveProcess on each other, hopefully making them unclosable. It works fine for one process(calling DebugActiveProcess for other process making it unclosable), but not for the other process. I don't know if there is anything else I need do do besides call DebugActiveProcess in each process.
Here is my code:
Process 1: Searches for other processes via window, and calls DebugActiveProcess on it
#include <windows.h>
#include <process.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
HWND hWindow=0;
do{
hWindow = FindWindowEx(NULL, NULL, "test","test");
Sleep(1000);
}
while(!hWindow);
SendMessage(hWindow, 0x55, _getpid(), NULL);
unsigned long id =0;
GetWindowThreadProcessId(hWindow, &id);
if(!DebugActiveProcess(id))
MessageBox(0,"Failed",0,0);
else
MessageBox(0,"Success",0,0);
while(true)
Sleep(1000);
return 0;
}
Process 2: Creates window, waits for message w/ other processes id in it, then calls DebugActiveProcess
#include <windows.h>
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case 0x55:
if(!DebugActiveProcess(wParam))
MessageBox(0, "Failed",0 ,0);
else
MessageBox(0,"Success",0,0);
break;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MsgProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(0);
wc.lpszMenuName = 0;
wc.lpszClassName = "test";
wc.hIconSm = 0;
RegisterClassEx(&wc);
CreateWindow("test", "test", 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
MSG msg;
while(true)
{
Sleep(1500);
PeekMessage(&msg, NULL, 0,0,PM_REMOVE);
}
}
Any ideas?