Only for Win9x users:
Here is an old version of the code.
It doesn't use Thread Local Storage so that it will fail in some special situations. Try it out and see if it works for your needs.
Printable View
Only for Win9x users:
Here is an old version of the code.
It doesn't use Thread Local Storage so that it will fail in some special situations. Try it out and see if it works for your needs.
Hi,
Thanks very much! I really appreciate the time you've taken to do this.
Steve
I was so desprate in finding an answer to my problems online...
and i think i got it here.... THANKS GUYS.
But i still got a problem again i guess.
I'm wonderfing if it's possible to ALTER the OUTPUT of a PROCESS before it gets to it's destination by hooking to it this way.
And if it's possible to track a call to another process from the hook process. This might help if you need to follow a particular procedure that jumps from one process to another.
THE MAIM PROBLEM IS ALTERING PROCESS OUTPUTS OR AT LEAST GETTING THEIR FUNCTIONS.
Thanks once more.
Hi moeur,
I'm stumped. Maybe you can help.
I've used this code for other projects and it works great.
I started a new project, and I'm simply trying to add fuctionality to an external app.
I've uploaded a demo of my problem maybe you can take a look.
I basically used your code to create this demo ( making sure it's not my code causing the problem).
I have say "Target Wnd" and setting a Hook for this wnd ( Works good ).
Next creating a new button in the "Target Wnd" and hooking it to watch for WM_LBUTTONUP\WM_LBUTTONDOWN.
This is unsuccessful. In fact something strange happens.
After adding message's to watch if you click the created button, the hookctl becomes visable ( But won't catch the message's ). Am I doing something wrong you can see?
Thanks for your help,
$hep
:::EDIT:::
Removed attachment per Hack - Edit Thank you! - Hack
The sources to these controls were posted in an earlier post by moeur..
$hep,
I took a quick look at your code.
I wasn't able to reproduce the problem that you describe, but I have a few comments as to why it doesn't work.
The button you create is created in the process and thread of the TestHook program and not the Target program.
To get messages for this button, you should be able to use standard subclassing and therefore don't have a need for the hook control.
What is your ultimate goal for the new button you create?
Hi moeur,
I see what your saying..
Well I'm trying to add buttons to an emulation window for like say "Quick Keys",
these will send a series of timed keys (using SendMessage) to do functions like "GetMail" about 60 keys "Do Reports" 32 etc...
So I need to get the messages from the hookctl ?
I don't need the hookctl for the buttons ?
Thanks for the input.
$hep
If you're not familiar with subclassing do a search in this forum for examples.
Once your button is subclassed, you'll get all its messages
Check this one
http://www.vbforums.com/showthread.php?t=334247
Hi moeur,
Thanks very much for your input.
It's much appreciated..
I'll try it from here.
Thanks again,
$hep
Hi guys have anyone succedded in making a hook to block WM_CLOSE/WM_DESTROY ??
Can any one supply a sample code for that ?
thank you in advance.
You can't change or discard WM_CLOSE or WM_DESTROY messages since they are "sent" not "posted".
One other note on this.
Although the title of this thread mentions "subclassing" it deals with hooking and not subclassing.
If you could actually subclass the external app, then you should be able to block the WM_DESTROY messages.
There is a way to truly subclass an external app. What you need to do is execute the code that initiates the subclassing from within the external process. A simple way to do this would be to first set a hook in the external process, then when the hook procedure is called, it will be running in the external process so you can then subclass the window you want to prevent from closing.
You can alter the dll code from this thread, or take a look at the link in my signature regarding injecting code into other processes to get more details on these methods.
dear moeur,
The Code is absolutely fantastic. But I have some problem. I want to record all the events occuring on an exe. Suppose I created an exe which is having 4-5 forms. I want that whenever I browse that exe using common dialog control and click a button named load it starts recording the events occuring on the exe on any of the forms or control of exe it should be recorded in a csv file. I also want that on keyup or keydown event it will also return the identification of the control and its parent where the event occured. for mousemove, mousedown and mouseup we can get the name of control using API WindowFromPoint but I want the identification of controls on key events also so that it will help me in playing back the events.
Please reply back soon.
Regards,
Smita
smita,
This could be done using the techniques laid out in this thread. You will also have to install a WH_SHELL hook to look for new windows opening.
If you want to use the control I wrote, then you'll have to instantiate one for each control on each form plus one for each form. You could find all the controls on a form using FindWIndowEx.
You would also have to add all messages you want to monitor. You say you want to monitor all messages; this is a lot of messages to add. Probably not pratical using my control.
So, use the code I wrote as a guide to produce your own code. You know there is a program out there that does all this,it's called SPY++ and comes with Visual Studio.
Good luck
Hi,
I am German and therefore i can't speak English so very well.
My friend had said that i can the traffic between ICQ and the ICQ Server monitored with this code. I want to see when somebody read my awaymessage.
My problem is, that I doesn't sure that this code can monitored the traffic. My friend can't help me. He had only heard this. I wants to be happy, when somebody help me. I hope all people understand me.
NEO
[QUOTE=moeur]This code uses a C++ dll and an ActiveX VB control to hook external programs.
Note: The source is included for both in case you want to change it or just learn from it.
--------------------------------->
notepad to Vb form work OK.
but, i wonder if it's possible to type sth in VB form--and let that keystroke(string) appear in Notepad? maybe by getting the Notepad handle using spy++? but, i do not understand the full concept and how to go about implement this. tq.
best regards,
jayzul
Send text to another program as you type
http://www.vbforums.com/showthread.php?t=368252
i've tried this code. work OK. notepad--to--VB form. how about from VB form--to--Notepad. keystroke in VB--keystroke send to VB form--VB form handle display.
how to change the code to do this. esp--to target specific handle.
Sorry, you lost me...
I thought you wanted to type something in a textbox in VB and have it show up in Notepad. No??
Hi moeur,
i really need this project converted to vb.net, i tried to just upgrade it to vb.net, and it gave me only 1 error. But unfortunetly i have never encountered this error before, so i cant do anything about it, maybe you can have a look at it.
thx
Filik,
I am sorry to say that I know almost nothing about .NET stuff so that you will have to post specific questions you might have to the .NET forum.
There is an excellent book on Subclassing and hooking in VB which includes two chapters on .NET.
http://www.oreilly.com/catalog/subhookvb/index.html
The example code is posted online. Here are examples of mouse and keyboard hooks in .NET as well as sublcassing examples.
http://examples.oreilly.com/subhookvb/Chapter22-23.zip
Good luck.
Quote:
Originally Posted by moeur
Thx, i'll have a look at the chapters, but i think the best way to go in this situation is to study the vb6 code and convert it manually.
rely nice code but i will try this code in my application
very good. I've already my code with your idea _ moeur; thaks
I've finally decided to enter the 21st century and learn .NET programming.
You will find the VB.NET version of this code in the .NET codebank
http://www.vbforums.com/showthread.p...51#post2383351
I was suprised at how easy it was to convert this code. The dll remains the same.
Hi Moer .. would this be a better alternative to tracking when an external program closes, instead of using EnumWindows in a Timer API. ..? Just curious before i start to dig through the code. .. using Enumwindows I am able to track most programs well, though MS Paint had so many issues i gave up on that program .. funily if i opened Paint hidden, used FindWindow to get the hwnd, then closed it, added a slight delay inbetween that, then opened it and used EnumWindows, it would work .. but still not 100% of the time when i was tracking other programs like MS Word, etc .. other programs work fine without findwindow though.
Thanks
Rory
Hi Moer,
Very very nice work. I can't tell you how much this is going to help my project. The DLL source is way over my head but I am certainly learning new stuff as I go thru it. What is the latest version of the code? The last post I saw of the DLL source said "Beta". (HookControl2.zip)
Thanks
The latest code is in the 1st post, it was updated in Oct 2005.
Any code posted in later posts was either a beta or a special version for someone's own situation.
Good luck with your project.
Hello! I was wondering if it is possible to make this work without the control part, as a class in C++ (to be used by a c++ application). The class would be instantiated like any other class...
I wasn't able to translate it myself (I'm not using VC++ 6, I have the Express edition which is VC++.NET).
Is it possible?
Just curious, in what cases does not using TLS fail?Quote:
Here is an old version of the code.
It doesn't use Thread Local Storage so that it will fail in some special situations. Try it out and see if it works for your needs.
Dawn of realisation :)
Without TLS, processes that have more than one thread may cause the hooking dll act in ways that are strange :).
scriptman,
It is possible to use without the VB control. Take a look at the code in the control to see how it interacts with the dll and you can mimick this in your C++ program. You'll need some type of a window to receive messages.
Raedwulf,
See Post #5 of this thread:
TLS handles the case of hooking two seperate threads that belong to the same process. Why this is a problem, is that each process only loads one copy of the dll. If this process has multiple threads they will all share the global data inside the dll. We need some mechanism of keeping a thread's global data private to that thread. This mechanism is called Thread Local Storage (TLS).
Hmmm.. This code works with the included sample and on a VB built app that I made. however, when I try and hook into a third party app, it's not receiving the messages, even though Spy++ can pick up the messages from the third party app. Do you know why this would be?
Woops, just found the answer. There are 2 controls on the third party app with the same class name. So how do I specify which one I want to hook into? There does not seem to be any other identifying information between the 2 controls so how in the world can you figure this out?
hi, the application is great, but whent i am trying to hook an application that contains 3 textbox control , it is getting only first text box! i want to hook all 3 .Is it possible? :confused:
Yes,
You need to have a hookcontrol for each textbox you want to hook.
Or you can use an array of hook controls.
Thanks for your reply... :)
i am not getting u! I want to hook all textbox controls of an external application. number of of text controls is not fixed. It varies. Is it possible? If yes, give me some idea to implement it.
Hello.
i've been using the hookdemo2 project to call my C++ dll from vb6.
i have it working perfectly when run in dev. however once i compile the exe it crashes without warning and vanishes completely ! this would seem to happen on the first intercepted message. every vb sub and function has error message handling but nothing is provided.
any ideas ? any help would be greatfully appreciated. i'm going mad ! :eek2:
In HookDemo2 Project Win32 API has used. Whenever API is used wrongly it generates error. U will never get time to check what is the problem. Check code carefully.
Plz attached the HookDemo2 project and the exe that will be hooked, so that i can help u!!