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);
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.


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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 160
difference between String.subString() and String.subSequence() 6 196
has77  challenge 9 85
How to convert MFC::CString to UTF8 wchar_t* 10 209
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 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