Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
3.00/5 (4 votes)
See more:

I'm trying to write an add-on for some program (which is written in .net v4.0.30319), but I cant figure out of to invoke functions of this other program.

For example, lets say the other 3th party program is this:

private void btnSomeButton_Click(object sender, EventArgs e)
    MessageBox.Show("This button has been pressed.");

Fist of all, to hook with the other progress I know I can either use

public static extern Int32 FindWindow(String lpClassName,String lpWindowName);



which is "better"?

next, given the first example of "private void btnSomeButton_Click"
* How do I even find the behind code/event of the button is btnSomeButton_Click
- I've been messing around with Microsoft Spy++ (which comes with VS, and with Reflector, but the program I'm "debugging" is rather big.

* How to I invoke that btnSomeButton_Click event from my own application? (additionally, how with parameters)

Thanks in advance, hope my question is understandable...

1 solution

None of your ideas will work.

A simple answer is: you the source code of that 3rd party application is not available, you cannot do it.

(I assume if you have the source code, this is not a problem at all, so I won't discuss this opportunity here.)

However, there is one remote opportunity: if you really know well how this 3-rd party application works and ready for extensive research, you can use is as a library and run some codes out of it in your process. Many developers don't know a simple fact that .NET *.EXE file is exact same thing as DLL, the major difference is its entry point. Formally, you can reference you *.EXE file exactly as DLL in your project, and it will work. This is very useful technique in some cases. However, in you cases this is not enough. Chances are, the types and methods you need are compiled as internal, private or internal protected. In this way, just a plain reference will not give you much. But if you want to use Reflection, you can open your *.EXE assembly using System.Reflection.Assembly and get access to all non-public declarations as well. How can you use this code, depends on the application and how much you know about its work (or are willing to experiment).

All other methods are… I would say, even worse. It depends on application though.

Share this answer
wizardzz 10-Mar-11 16:54pm    
Good advice, 5
Sergey Alexandrovich Kryukov 10-Mar-11 17:19pm    
Thank you,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900