Windows Messages

D

Dracolytch

Hey all,
I'm looking for a way to view all of the windows messages, like Spy ++
does. It's fairly trivial to do it for the current application, but how can
I take that knowledge to the bigger (system-wide) picture?

Thanks,
~D
 
P

Peter Huang

Hi,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.

From your description, I understand that you wants to know how to monitor
all the windows messages in System Wide From VB.NET something like Spy++?
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think you may need to use the Hook technique to set an system-level
Global Hook to WH_GETMESSAGE.

But Global Hook is Not Supported in .NET Framework

You cannot implement global hooks in Microsoft .NET Framework. To install a
global hook, a hook must have a native DLL export to insert itself in
another process that requires a valid, consistent function to call into.
This requires a DLL export, which .NET Framework does not support. Managed
code has no concept of a consistent value for a function pointer, because
these function pointers are proxies that are built dynamically.

319524 HOW TO: Set a Windows Hook in Visual Basic .NET
http://support.microsoft.com/?id=319524


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
H

Herfried K. Wagner [MVP]

* "Dracolytch said:
I'm looking for a way to view all of the windows messages, like Spy ++
does. It's fairly trivial to do it for the current application, but how can
I take that knowledge to the bigger (system-wide) picture?

You will have to set up a global message hook ('WH_GETMESSAGE'). Maybe
you can base your sample on this example program written by Paul Kimmel:

<http://www.developer.com/net/net/article.php/11087_2193301_1>
 
C

CJ Taylor

Herfried,

this is a really good article, however I have a question for you. Now, the
way I understand Global Hooks is that its not possible in .NET because it
cannot be exported like a regular DLL into other processes. (I knew this
before Peter made his statement).

I have recently been trying to do global hooks in .NET with mouse events,
now, looking at this article, I wonder, is the same possible or am I
misreading this article as a global hook solution?

Thanks,
CJ
 
H

Herfried K. Wagner [MVP]

* "CJ Taylor said:
this is a really good article, however I have a question for you. Now, the
way I understand Global Hooks is that its not possible in .NET because it
cannot be exported like a regular DLL into other processes. (I knew this
before Peter made his statement).

I have recently been trying to do global hooks in .NET with mouse events,
now, looking at this article, I wonder, is the same possible or am I
misreading this article as a global hook solution?

I didn't have a closer look at Paul's solution and I always thought that
it's impossible to implement a global hook using .NET. I am not sure,
if Paul's implementation is "stable" or if it's a "dirty" hack.
 
T

Tom Shelton

Herfried,

this is a really good article, however I have a question for you. Now, the
way I understand Global Hooks is that its not possible in .NET because it
cannot be exported like a regular DLL into other processes. (I knew this
before Peter made his statement).

I have recently been trying to do global hooks in .NET with mouse events,
now, looking at this article, I wonder, is the same possible or am I
misreading this article as a global hook solution?

Thanks,
CJ

Low level hooks are possible in .NET - but you should be aware that
WH_KEYBOARD_LL and WH_MOUSE_LL only work on NT based systems. If you
want this to work on any Windows OS, you'll need to use WH_KEYBOARD.
And, you can't set a global hook using WH_KEYBOARD from VB.NET...

It is fairly trivial to implement the hook as a C/C++ dll and then call
it from your VB.NET app. If you need an example, let me know. I have
some code I wrote to do this that I could post.
 
C

CJ Taylor

Actually, if you have some global hook c++ code for the mouse that would be
awesome... I'm sure I could find some online but hell, why bother.

my email is
cege at839-0- tavayn 3830dot 3422com342

remove numbers and dashes.
 
T

Tom Shelton

Actually, if you have some global hook c++ code for the mouse that would be
awesome... I'm sure I could find some online but hell, why bother.

my email is
cege at839-0- tavayn 3830dot 3422com342

remove numbers and dashes.

CJ,

I haven't forgotten you or not noticed this message... Unfortunately,
the sample code that I had written seems to be among the bunch I lost to
a HD crash a few months ago... Never fear, I worked on putting a little
sample together today. I expect that I will be able to post the results
sometime tommorow :)
 
C

CJ Taylor

Tom,

Much appreciated, I really look forward to seeing it and greatly appreciate
you taking the time to show me.

Thanks,
CJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top