Solved

Calling Sendmessage from MFC extension dll

Posted on 2001-07-19
7
438 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

12 Experts available now in Live!

Get 1:1 Help Now