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