Link to home
Start Free TrialLog in
Avatar of joEpmEloEn
joEpmEloEn

asked on

Calling Sendmessage from MFC extension dll

Hi everybody.
I'm having some problems with my MFC extension dll.
I want to call SendMessage from it, so that the exe file (dialog base MFC) can handle the message send by the dll.
How do I send a message from the dll?
I haven't got a window.
I tried to send the CWnd pointer from AfxGetMainWnd() to the dll (I have an AFX_EXT_CLASS defined), but in the dll I receive an empty pointer (I can send an integer to the dll).
Does this have something to do with memory allocation?
I hope somebody can help me with this.
Thanks in advance.
Greetz joEp mEloEn
Avatar of migel
migel

Hi!
you can or find needed window or get current active window by GetActiveWindow();
Also you can pass window handle to the DLL through DLL function calling:
for example:
SetDLLNotifyReciever(HWND hwnd)
{
}
and after that use passed handle to send message to that window
Avatar of joEpmEloEn

ASKER

Could you be more specific please.
Could you give me a little sample maybe?
Thanks for the reply.
Greetz joEp mEloEn
What sample???
calling SendMessage API???
or caling DLL function???

make this
// declare it as dllexport /dllimport
//exportable function;

// in the DLL module declare static variable:
static HWND g_hwndReciever = NULL;

void SetDLLNotifyReciever(HWND hwnd)
{
g_hwndReciever = hwnd;
}

// in the place where you want send message:
::SendMessage(g_hwndReciever, WM_MY_MESSAGE, 0, 0);
I can call GetActiveWindow() from my exe file, but that returns an CWnd*. What do I have to use???
Thanks
Greetz joEp mEloEn
And by the way, I can't declare the static variable in my dll. I get this error:
error C2252: 'g_hwndReciever' : pure specifier can only be specified for functions
ASKER CERTIFIED SOLUTION
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, I just wasn't paying very much atention.
Thanks for you answer.
Greetz joEp mEloEn