Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Win32 (http://www.go4expert.com/forums/win32/)
-   -   update field message from win32 dll to dialog app (http://www.go4expert.com/forums/update-field-message-win32-dll-dialog-t918/)

goT 21Jun2006 20:58

update field message from win32 dll to dialog app
 
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 22Jun2006 10:31

Re: update field message from win32 dll to dialog app
 
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 22Jun2006 10:35

Re: update field message from win32 dll to dialog app
 
Moved to a new thread rather than the other old thread.

goT 22Jun2006 11:59

Re: update field message from win32 dll to dialog app
 
1 Attachment(s)
it still did not get resolved. see attachment.

shabbir 22Jun2006 14:08

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

goT 22Jun2006 16:56

Re: update field message from win32 dll to dialog app
 
Uh, yes when i was in debug mode it was unused. that is right. how do i get hndle of the app then?.

shabbir 22Jun2006 18:09

Re: update field message from win32 dll to dialog app
 
You can pass that to the DLL or use the FindWindow function to get the handle.

goT 23Jun2006 08:12

Re: update field message from win32 dll to dialog app
 
thank you.


All times are GMT +5.5. The time now is 21:10.