Solved

Calling Sendmessage from MFC extension dll

Posted on 2001-07-19
7
441 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now