Add program to my application

Oct 22, 2013 at 11:12 AM
How can i include this program to my application? Is it exist any method to enable this?
Oct 22, 2013 at 1:15 PM
Edited Oct 22, 2013 at 1:24 PM
You don't give many details as how you'd like to "include" Hawkeye in another application. I already answered a similar question here (it concerns Hawkeye2, but is similarly applicable to your question):
Marked as answer by odalet on 10/22/2013 at 5:15 AM
Oct 23, 2013 at 6:54 AM
I saw source code and understand that it is possible to add a button to my program. When user press this button the Hawkeye will start.
So in button's handler i write something like:

But my problem is next. My application build under AnyCPU NET 3.5. So if it is not possible to build Hawkeye in AnyCPU some error can appeared.
In Hawkeye2 i saw that main program is under AnyCPU, so i can try to add reference

and in button handler write: HawkeyeApplication.Run()

And one more question about Hawkeye2. Now it show all properties of control, even invisible. Is some settings exists to turn this off?
Oct 23, 2013 at 7:00 AM
"Now it show all properties of control, even invisible. Is some settings exists to turn this off?"
I ask this because in Hawkeye1 for me is more ease to get needed properties (i usually see property DataBinding). But in Hawkeye2 it is enough difficult
Oct 23, 2013 at 9:08 AM
Preamble: I'd wish to say it's been quite a long time (I have other projects under the hood that are of bigger priority to me than the 2 Hawkeye projects) I didn't dive into Hawkeye source code and thus I don't guarantee the full exactness of what I'll say below. Only trying to code something similar to what you need would be an ultimate proof (note that because your problem seems interesting, I may try something like this at some point in time...).

General considerations: both Hawkeye and Hawkeye2 were designed to be standalone tools. They provide (both in a different way and with different capabilities) some sort of an extensibility model, but designed as means to extend Hawkeye capabilities, not to make Hawkeye part of a bigger system. In short, Hawkeye as an embeddable library does not exist (yet an idea worth exploring, though seems to be a difficult goal).

All this legal being stated, let's take things in order:

It's not because Hawkeye's exe was built in AnyCpu that it will run as expected if you reference it from your program: the main executable is nothing but a bootstrapper that needn't be tied to a specific platform. Though other assemblies it depends on may be tied to a specific platform. The selection of the correct assembly to load is made dynamically when you spot a window (with the target cursor) by examining the window's owning native process.

Your chances at successfully doing what you try are related to the way you intend to use Hawkeye from your application: what do you want to inspect? Your own application (ie. the process that started Hawkeye)? Or any application? Both cases are very different. Let me explain why:

You must understand that in order for Hawkeye to give you information about a running .NET process, it must inject itself into the process. Honestly this is the most tricky part of Hawkeye (and which involves gory Managed C++ and native magic). Concretely, when a process is detected, Hawkeye looks for its itself but in the correct version (correct .NET: 2 or 4, and correct bitness: x86 or x64) then runs this version, passing it the pid/hwnd handles so that it hooks in the spied process. During this process you may see the Hawkeye window flashing. This happens when the original hawkeye closes and the hooked hawkeye starts. When started in this "hook" mode, it is no longer the Hawkeye.exe process that is running, but the spied application itself; now, Hawkeye is just some code part of, belonging to the spied process! Imagine Hawkeye is some sort of virus that lives in the application you want to examine.

There is one case where Hawkeye doesn't have to inject: it is when you inspect Hawkeye itself (and this is completely legal). In this case, there is no need for process detection, then injection, because, obviously, Hawkeye's code is already part of Hawkeye :).

So, if you only intend to inspect your own application, referencing Hawkeye may work, because the injection logic hasn't to be called, and then Hawkeye provides you with rather regular reflection and a nice property grid.

On the contrary, if you want to spy other processes and all you want is a button to launch Hawkeye, then I wouldn't try to reference Hawkeye, but rather to simply run the Hawkeye process when you click the button (use System.Diagnostics.Process.Start).

To sum it up: I didn't distinguish here between Hawkeye and Hawkeye2, there may be differences between the two, something working with one and not the other. Anyway, both programs work very similarly and share the same concepts. So you're left with guess and try...

PS: concerning the way Hawkeye2 shows properties, it's just the way I like it, but you're right, it may be a bit confusing to get so much information, and I may tweak the UI to add a Hawkeye 1-like view. At the moment, no setting exists (nor is planned).

Hope all this helps you.

PS: please tell me more about your scenario (do you spy your own application or others).
Oct 23, 2013 at 9:41 AM
I will spy my own apllication
Oct 23, 2013 at 9:51 AM
OK, so if I can get some time for myself I'll try to make a demo app doing that.