update field message from win32 dll to dialog app

goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
win32 c++ dll code:
Code:
#include <windows.h>
HINSTANCE ghModule = 0;          //module handle
HWND       ghwnd ; 
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		ghModule = (HINSTANCE) hModule;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
    return TRUE;
}

CDLLClass::CDLLClass()
{
	return;
}

CDLL BOOL SendToApp(int ID, int i)   /* this by itself did not work for me*/
{ 
	ghwnd = (HWND) ghModule;
     SendMessage(ghwnd,     // handle of destination window
                    ID,     // message to send 
                    i,     // first message parameter
                    0 );     // second message parameter

     return true;
}

int SetHook(int idHook, HOOKPROC lpfn)
{
	if (idHook == WH_GETMESSAGE)
	{
		if(gHGHook != NULL)
		{
			return -1;
		}
		
		gHGHook = SetWindowsHookEx(WH_GETMESSAGE, lpfn, gInstance, 0);
	}
	
	return 0;
}

int UnHook(int idHook)
{
	if (idHook == WH_GETMESSAGE)
	{
		if(gHGHook == NULL)
		{
			return -1;
		}
		UnhookWindowsHookEx(gHGHook);
		gHGHook = NULL;
	}
	
	return 0;
}

int CallNextHook(int idHook,
				 int nCode,
				 WPARAM wParam,
				 LPARAM lParam)
{
	if (idHook == WH_GETMESSAGE)
	{
		if(gHGHook == NULL)
		{
			return -1;
		}
		CallNextHookEx(gHGHook, nCode, wParam, lParam);
	}
	
	return 0;
}

int StartHook(HWND hApp, HWND hExcel, const CString &str)
{
	gApp = hApp;
	gExcel = hExcel;
	SetHook(WH_GETMESSAGE, GetMsgProc);
	return 0;
}

int StopHook()
{
	UnHook(WH_GETMESSAGE);
	return 0;
}
this is part of my code for dialogapp.cpp:

Code:
#define WM_U_Ctrl WM_APP + 0x100
//imported it: BOOL SendToApp(int ID, int i);

void CappDlg::OnBnClickedButton1()
{
	SendToApp(WM_U_Ctrl, 1);
	//SendMessage(WM_U_Ctrl, 5, 0);
}

LRESULT CappDlg::OnUpFromDll(WPARAM wParam, LPARAM lParam)
{
	SetDlgItemInt(IDC_EDIT1,wParam,lParam);
	return 0;
}
I was wondered how to send update field message from win32 dll to dialog app.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by goT
I was wondered how to send update field message from win32 dll to dialog app
Use the ::SendMessage or ::PostMessage functions.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to a new thread rather than the other old thread.
goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
it still did not get resolved. see attachment.
Attached Files
File Type: zip dlls.zip (36.7 KB, 12 views)
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Actually you are not sending the message to the Window App window but sending it to the current instance of the dll because ghModule is the dll handle.
goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
Uh, yes when i was in debug mode it was unused. that is right. how do i get hndle of the app then?.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You can pass that to the DLL or use the FindWindow function to get the handle.
goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
thank you.