Click here to Skip to main content
15,887,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have written application for WH_SHELL and WH_CBT hooking,the problem with this application is that i'm able to hook window created messages but for window destroy messages my application just crashes,if i comment the window destroy code the application works fine,i have google it and found no solution.My ultimate concern is how can i handle window destroy message in this application.Posting the necessary code snippet below
this is my hooking dll
C++
LRESULT CALLBACK HookProc (int nCode, WPARAM wParam, LPARAM lParam )
{		        
	if (nCode == HCBT_KEYSKIPPED && (lParam & 0x40000000))
	{        
		
	}
	else if (nCode == HCBT_SETFOCUS)
	{
		::PostMessage(g_hSpyWin, MSG_MY_WM_SETFOCUS, wParam, lParam);
	
	}
	else if(nCode==HSHELL_WINDOWCREATED)
	{
		::PostMessage(g_hSpyWin,MSG_MY_WM_ACTIVATE,wParam,lParam);
	}
	else if(nCode==HSHELL_WINDOWDESTROYED)
	{
		::PostMessage(g_hSpyWin,MSG_MY_WM_DESTROY,wParam,lParam);
	}
	return CallNextHookEx( 0, nCode, wParam, lParam);
}

this is my main function,here i call another function OnNewCreateWindow() which does nothing but writes information about created window into file.
C++
LRESULT OnNewWindowCreate(WPARAM wParam,LPARAM lParam)
{
	
	thwnd=(HWND)wParam;
	OnNewCreateWindow1(thwnd);
	return S_OK;
}

LRESULT On_WindowDestroy(WPARAM wParam,LPARAM lParam)
{
	dHwnd=(HWND)wParam;
	MessageBox(NULL,"Into destroy window function","Destroy",MB_OK);
	//OnWindowDestroy1(dHwnd);
	return S_OK;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message == MSG_MY_WM_KEYDOWN)
		return OnInterceptKeyStroke(wParam, lParam);

	if (message == MSG_MY_WM_SETFOCUS)
		return OnSetKeyboardFocus(wParam, lParam);

	if(message==MSG_MY_WM_ACTIVATE)
		return OnNewWindowCreate(wParam,lParam);

	if(message=MSG_MY_WM_DESTROY)
		return On_WindowDestroy(wParam,lParam);
		

	switch (message)
	{	
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
		
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}


Here in the destroywindow function i have entered a messagebox() when i execute the application it just shows the messagebox twice and then exists the application.i dont know where i'm going wrong or what should i do more to handle the destroy window msg,same happens if i use
Posted
Updated 7-Jan-13 12:40pm
v2

1 solution

HEY finally found a work around,instead of hooking HSHELL_WINDOWDESTROY message i just use the handle returned from HSHELL_WINDOWCREATED to get the process id using which i could get the handle to process,i stored the process id,handle to process in a singly link list and then wrote a checking function in thread which would check every 1000 ms that a process is terminated or not using the values process id and handle to process from link list,if its terminated i simply retrieve its End time and store it for the same entry in the link list.Hence i could get both the start and end time of the process...
I thought instead of pondering on solution why not get a work around...
Thank you guys...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900