Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling Sendmessage from MFC extension dll

Posted on 2001-07-19
7
Medium Priority
?
478 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:joEpmEloEn
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6297413
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
0
 

Author Comment

by:joEpmEloEn
ID: 6297490
Could you be more specific please.
Could you give me a little sample maybe?
Thanks for the reply.
Greetz joEp mEloEn
0
 
LVL 12

Expert Comment

by:migel
ID: 6297505
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);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:joEpmEloEn
ID: 6297535
I can call GetActiveWindow() from my exe file, but that returns an CWnd*. What do I have to use???
Thanks
Greetz joEp mEloEn
0
 

Author Comment

by:joEpmEloEn
ID: 6297544
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
0
 
LVL 12

Accepted Solution

by:
migel earned 800 total points
ID: 6297576
You declare it in the header???
also why you call GetActiveWindow from EXE???
you can simple call

SetDLLNotifyReciever(m_hWnd);
in the your dialog WM_INITDIALOG handler.
0
 

Author Comment

by:joEpmEloEn
ID: 6297603
Thanks, I just wasn't paying very much atention.
Thanks for you answer.
Greetz joEp mEloEn
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Loops Section Overview

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question