exe call method of another exe

  • Thread starter Thread starter Steph
  • Start date Start date
S

Steph

hello,
i have two application,
Application 1 : with a method :
public int math_add(int a, int b)
{ return a+b;}

and a another application 2 :
Process[] NewProcessList2 =
Process.GetProcessesByName("WindowsApplication1TEST");
foreach (Process TempProcess in NewProcessList2)
{
// BUG :
TempProcess.MainModule.GetType().GetMethod("math_add").Invoke(TempProcess.MainModule,
new object[] { 2,3 });
}

how do... call a method of another running exe...



thanks



steph
 
Why do the logic in application 1 need to be an exe/standalone application?
Business logic methods such as your math_add method is normally placed in a
class library assemblies (DLL), which you can then add a reference to (in x
number of projects).
The calls would then go in-process, which would perform better as well as be
a less fragile solution (code would be cleaner and you will never have to
deal with questions like 'what if application 1 has died').
If you really need to go cross-process, you may want to check out .NET
remoting or Web Services.

But really, for methods like "math_add", nothing but a class library makes
sense to me.

Hope it helps

Tor Bådshaug
tor.badshaug(AT)bekk.no
 
Hey Steph,

I would strongly recommend if possible that you abstract the logic you
want to be called into a separate DLL. You will then realize benefits
such as security and improved performance.

As to whether what you're suggesting is possible .. Let me try and see
if I can do it.
hello,
i have two application,
Application 1 : with a method :
public int math_add(int a, int b)
{ return a+b;}

and a another application 2 :
Process[] NewProcessList2 =
Process.GetProcessesByName("WindowsApplication1TEST");
foreach (Process TempProcess in NewProcessList2)
{
// BUG :
TempProcess.MainModule.GetType().GetMethod("math_add").Invoke(TempProcess.MainModule,
new object[] { 2,3 });
}

how do... call a method of another running exe...



thanks



steph
 
Steph said:
hello,
i have two application,
Application 1 : with a method :
public int math_add(int a, int b)
{ return a+b;}

and a another application 2 :
Process[] NewProcessList2 =
Process.GetProcessesByName("WindowsApplication1TEST");
foreach (Process TempProcess in NewProcessList2)
{
// BUG :
TempProcess.MainModule.GetType().GetMethod("math_add").Invoke(TempProcess.MainModule,
new object[] { 2,3 });
}

how do... call a method of another running exe...



thanks



steph

Hi Steph,

Not like that, unfortunately. The process is slightly more complicated...
Which version of .NET are you using? And do you have access to the source
code to /both/ applications?
 
hi,
further information :
i access to the source... its my programs.
i'am under c# 2...
and its not a simple math method...
unfortunately, i need to use a
"myThread.SetApartmentState(ApartmentState.STA);"...
cause... i need to create a object window form needly a apartmentstate...
and if i use my method into a dll or comandline, my program work if lunch
into VS2005, but not work on standalone mode.
i can arrive to do work it if i put a lot a MessageBox ... (????)...

so... i created a exe... put into my method, all is working, but now, i need
to call a public method to launch my program from another exe or shell
command.

steph



Tom Spink said:
Steph said:
hello,
i have two application,
Application 1 : with a method :
public int math_add(int a, int b)
{ return a+b;}

and a another application 2 :
Process[] NewProcessList2 =
Process.GetProcessesByName("WindowsApplication1TEST");
foreach (Process TempProcess in NewProcessList2)
{
// BUG :
TempProcess.MainModule.GetType().GetMethod("math_add").Invoke(TempProcess.MainModule,
new object[] { 2,3 });
}

how do... call a method of another running exe...



thanks



steph

Hi Steph,

Not like that, unfortunately. The process is slightly more complicated...
Which version of .NET are you using? And do you have access to the source
code to /both/ applications?

--
Hope this helps,
Tom Spink

Google first, ask later.
 
I am sorry, but I find this a bit hard to read let alone understanding it.
You are controlling the source of both programs, that's good for a start.
Exactly what is not working when you put your method into a class library
DLL?

Tor Bådshaug
tor.badshaug(AT)bekk.no
 

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

Back
Top