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