Log interop Win32 messages in a C# application - Repost

M

michelQQA

First, this thread is not releated to C# or net framework but after
trying to post in interop and C++ workgroups, I never receive any
answer or something to start with.

I'm doing a kind of macro recording tool to record user actions in
another application. I can easily manage keyboard and basic mouse
operation with a global low level mouse/keyboard hook but i need to
trap other messages like WM_COMMAND and behing able to get
notifications (ex:CBN_SELCHANGE)

I other words I need to do exactly like Spy++ when logging windows
message of a particular handle.

I suppose I need to find a way to override the window proc of window
of an unmanaged application in a managed application. After playing
for weeks with hooks, dll, learning native things and searching all
over the net I still have no clue. Any example or the main steps
would be usefull

Thanks and sorry again for posting here.
 
K

Kerem Gümrükcü

Hi Michael,

i dont understand you if you say you did this all with
hooks. There is a simple method with SetWindowsHookEx(...)
to do this:

http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx

the you ise in idHook a type fo WH_CALLWNDPROC so you will
get any messages the windows receives,...

But if you want to hook something in deeper, then you should
inject a dll into the target application and then load your inject
library into the target applications memory space and then hook
every function you want to hook in the memory space of the
injected code,...

So i guess this migth be of some help:
http://www.codeproject.com/KB/system/WilsonSystemGlobalHooks.aspx

and this when it comes to code injection:

http://www.codeproject.com/KB/threads/winspy.aspx

Regards

Kerem
 
J

Jason Newell

I just answered your post in the Interop newsgroup and just happened to
notice your post here. Here is my answer from the other newsgroup.

http://support.microsoft.com/kb/815775

See the last part section named "Subclass Any HWND". The jist of it is
that you need to create a class and inherit from the NativeWindow class.
After you override the WndProc and call AssignHandle(), you'll get the
messages for the given window. Don't forget to ReleaseHandle() when
you're done.

Jason Newell
Software Engineer
 
M

michelQQA

Thanks Kerem and Jason :)

With Jason's kb link I was able to catch messages in the SAME thread
of my application. By using a library injection example I was also
able to catch messages from different threads/windows :)

I need to learn more about dll injection and hooks to simply inject
the class and the code :
SubclassHWND s = new SubclassHWND();
s.AssignHandle(WindowsHandleToWatch);

Will play with this for the next two days... still not really clear
how this will be merged to the keyboard/mouse hook mixed with the
other hook and code injection for subclassing (for my macro recording
application)

Thanks again, this is exactly what I need!!
 
J

Jason Newell

Your dll injection comment reminded me of an OpenGL injection that I
once tried (successfully). Microsoft Research has a product called
Detours for this kind of thing. It's actually quite amazing. Did
exactly what I wanted but the licensed version was $10,000 USD at the
time. So I had to bail on the project.

http://www.microsoft.com/iplicensing/productDetail.aspx?productTitle=Detours
http://research.microsoft.com/en-us/projects/detours/

I bring it up because it may give you some needed tips for what you're
wanting to do.

Jason Newell
Software Engineer
 

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

Top