1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

update field message from win32 dll to dialog app

Discussion in 'Win32' started by goT, Jun 21, 2006.

  1. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Use the ::SendMessage or ::PostMessage functions.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Moved to a new thread rather than the other old thread.
     
  4. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    it still did not get resolved. see attachment.
     

    Attached Files:

  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    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.
     
  6. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Uh, yes when i was in debug mode it was unused. that is right. how do i get hndle of the app then?.
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    You can pass that to the DLL or use the FindWindow function to get the handle.
     
  8. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    thank you.
     

Share This Page