Click here to Skip to main content
15,905,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a .net application "A" (but no source code available). I have a c# application "B" with source code. I need to call B from A on click of a button.

If yes, could you please share some ideas.

Thanks in Advance
Venkat
Posted
Comments
Olivier Levrey 23-Feb-11 3:42am    
I think this is doable through reflection but this certainly not a good idea. What does this button do at the first place in the application "A"?
Sergey Alexandrovich Kryukov 23-Feb-11 3:55am    
Not only through reflection. Nobody said it should be the same way. Reflection is not wrong either.
Do you mean finding something by name? Of course very bad. How about special assembly attribute (reference from another assembly by both referencing and referenced), which should point out what class to load? There are very safe methods, if you use some thinking...
Please see my Answer...
--SA

See Process.Start[^] - it allows you to execute any executable from within your program.
 
Share this answer
 
Comments
Venkat Eswaran 23-Feb-11 3:28am    
Since I dont have the source code for Application A. I cannnot insert this code into it. Any clues in reflection.
Sergey Alexandrovich Kryukov 23-Feb-11 3:52am    
My 5, but... do you know a very different way I describe in my Answer? It's very useful in some cases and perfectly legal.
--SA
Olivier Levrey 23-Feb-11 4:09am    
Why 5? This doesn't solve OP's problem at all...
Sergey Alexandrovich Kryukov 23-Feb-11 4:28am    
Simply because OP does not describe what is a "call" of application. Griff took the most trivial of the possible meanings and offered the Answer: "call" is actually interpreted running the process using entry point. What's so wrong with it?

If you disagree, put you vote and would you please explain what's wrong?

--SA
Olivier Levrey 23-Feb-11 4:51am    
OP sayed: "I want to start application 'B' from a button contained in application 'A', but I don't have source code of 'A'"... Application.Start would be nice inside 'A' but since OP can't modify its source code, this can't be the solution.
There is another way, often a better way. Unlike native *.DLL and *.EXE, in .NET there is no principal difference between *.DLL and *.EXE (surprise!). Of course, a library cannot be started from Shell as *.EXE, but the opposite is perfectly legitimate: you can use *.EXE like a normal library (surprise!): reference it statically or load dynamically using Reflection to find an entry point you want (not only "standard" entry point).

This operation will be quite different: the code of executable will run in the same process; new process will not be created.

—SA
 
Share this answer
 
Comments
Olivier Levrey 23-Feb-11 4:08am    
I knew *.exe could be loaded as a library (I already did it once). But I doubt OP can access the button he wants like that since this button should be public in a public class... am I wrong?
Sergey Alexandrovich Kryukov 23-Feb-11 4:23am    
Yes and no.

Too things: 1) for Reflection, all is visible. 2) OP does not say if the "called" assembly's source code is available or not. If it is, one can make public whatever desired.

Please understand, I just bring "yes another" possibility which is not, formally speaking, disqualified by the Question as it is formulated, so why not? A legitimate Answer, useful to know... is it not?

--SA
Olivier Levrey 23-Feb-11 4:59am    
Indeed, loading an Exe as a library is something interesting to know.
1) For reflection, all is visible: I agree. But it doesn't mean we can access private components (instanciating private classes, calling private methods, ...).
2) Unless I can't read properly (or maybe my english level makes me understand things unproperly), OP said he has 'B' source code but he doesn't have 'A' source code...
Venkat Eswaran 23-Feb-11 5:01am    
Sorry for the confusion. I meant "Call" in the context. Application A should execute Application B on click of a button from A. Mimic the following code code from application A


private void button1_Click(object sender, EventArgs e)
{

Process.start("ApplicationB.exe");

}
Olivier Levrey 23-Feb-11 5:10am    
OK forget what I said then. OriginalGriff and SA are right --> 5 for both!

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