Click here to Skip to main content
15,881,757 members

Handling wh_shell's window destroy message

analogx asked:

Open original thread
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
Tags: C++, DLL, Hooking

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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