Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Calling Sendmessage from MFC extension dll

Posted on 2001-07-19
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
Question by:joEpmEloEn
  • 4
  • 3
LVL 12

Expert Comment

ID: 6297413
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

Author Comment

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

Expert Comment

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);
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

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

Author Comment

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
LVL 12

Accepted Solution

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

in the your dialog WM_INITDIALOG handler.

Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 52
fizzArray  challenge 1 96
EvenOdd challenge 10 125
How do I get Window Title of all opened process? 4 12
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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