Discussion:
How to send Mouse events to dll
(too old to reply)
divya_rathore
2011-06-15 23:12:20 UTC
Permalink
Scenario:
In an MDI environment, I need to send the mouse events (OnLButtonDown/
Up, MouseMove etc.) performed on an MDI child window to a dll. What
would be the best way to achieve this?

Is creating a function (whose arguments are same as OnLButtonDown/Up,
MouseMove etc.) in the dll and calling it in the app's view (in
OnLButtonDown) using GetProcAddress an ideal way of doing this?

Or are there some more apt ways of doing this? Has hooking anything to
do with what I intend to do (here's Joe's article on hooking:
http://www.codeproject.com/KB/DLL/hooks.aspx)?
Joseph M. Newcomer
2011-06-16 01:15:37 UTC
Permalink
The concept of "sending a message to a DLL" is completely meaningless. There is no
mechanism for sending a message to a DLL, because it is about as meaningful as asking how
to refrigerate a DLL, or fry one. DLLs do not receive messages, because only windows
receive messages.

Messages are sent to windows. In MFC, a message which is routed to a window is dispatched
to a handler via a message map table entry. The concept of a DLL is irrelevant to this
discussion, because the message map doesn't care where the handler is located.

Note that a DLL can contain code to create a window, and you can call that code, and the
window belongs to the thread that called the function that created the window. That
window can receive messages, but they are not sent to the DLL, they are sent to the
window.

Now, if you want to call a function in a DLL, you call the function in the DLL. It's just
a call. GetProcAddress is irrelevant unless you are using LoadLibrary to load the DLL;
otherwise you just link with the .lib file that is produced when you link the DLL.

Hooks are a completely different concept, not related to window messages. While some
hooks are indeed hooking window messages, the act of sending messages is not related to
the concept of hooks as such; they are just hookable events. But you would never consider
using this as a way of getting information from your app to code in the DLL.

The simple solution is to create methods in the DLL that handle the events, and call them.
Whether you call them directly from the message map, or put a call in the normal handler,
is largely irrelevant. The call will still work.
joe
Post by divya_rathore
In an MDI environment, I need to send the mouse events (OnLButtonDown/
Up, MouseMove etc.) performed on an MDI child window to a dll. What
would be the best way to achieve this?
Is creating a function (whose arguments are same as OnLButtonDown/Up,
MouseMove etc.) in the dll and calling it in the app's view (in
OnLButtonDown) using GetProcAddress an ideal way of doing this?
Or are there some more apt ways of doing this? Has hooking anything to
http://www.codeproject.com/KB/DLL/hooks.aspx)?
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
divya_rathore
2011-06-16 08:50:23 UTC
Permalink
On Jun 16, 2:15 am, Joseph M. Newcomer <***@flounder.com> wrote:
...
...
Post by Joseph M. Newcomer
The simple solution is to create methods in the DLL that handle the events, and call them.
Whether you call them directly from the message map, or put a call in the normal handler,
is largely irrelevant.  The call will still work.
                                joe
Thanks, Joe. Very helpful!
David Webber
2011-06-17 20:05:41 UTC
Permalink
"Joseph M. Newcomer" wrote in message news:***@4ax.com...

...Now, if you want to call a function in a DLL, you call the function in
the DLL...

I have my own way of doing this.

My 1st level document and view are derived from CDocument and CView as
classes defined in, and exported from, an MFC extension DLL.

Schematically

class CDoc1 : public CDocument;
class CView1 : public CView;

These classes handle a lot of common tasks (including drawing the view).

Now I have two programs each with its own executable with

class CDoc2a: public CDoc1;
class CView2a: public CView1;

class CDoc2b: public CDoc1;
class CView2b: public CView1;

Now The '2a' program is my Mozart music editor and the '2b' program is my
free mozart viewer which prints and plays but does not edit. The share a
lot of code at the DLL (1) level, but have a completely different
capabilities at the exe level - level 2.

This has proved a very maintainable solution for me, but is perhaps
complicated enough that you'd only attempt it if there were significant
benefits.

Dave

-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Joseph M. Newcomer
2011-06-17 22:33:13 UTC
Permalink
Good point; I had avoided going to that level of detail, We did a similar thing for
licensing a distributed server-management tool.
joe
Post by David Webber
...Now, if you want to call a function in a DLL, you call the function in
the DLL...
I have my own way of doing this.
My 1st level document and view are derived from CDocument and CView as
classes defined in, and exported from, an MFC extension DLL.
Schematically
class CDoc1 : public CDocument;
class CView1 : public CView;
These classes handle a lot of common tasks (including drawing the view).
Now I have two programs each with its own executable with
class CDoc2a: public CDoc1;
class CView2a: public CView1;
class CDoc2b: public CDoc1;
class CView2b: public CView1;
Now The '2a' program is my Mozart music editor and the '2b' program is my
free mozart viewer which prints and plays but does not edit. The share a
lot of code at the DLL (1) level, but have a completely different
capabilities at the exe level - level 2.
This has proved a very maintainable solution for me, but is perhaps
complicated enough that you'd only attempt it if there were significant
benefits.
Dave
-- David Webber
Mozart Music Software
http://www.mozart.co.uk
For discussion and support see
http://www.mozart.co.uk/mozartists/mailinglist.htm
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Loading...