473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

exe call method of another exe

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("WindowsApplication1TES T");
foreach (Process TempProcess in NewProcessList2)
{
// BUG :
TempProcess.MainModule.GetType().GetMethod("math_a dd").Invoke(TempProcess.MainModule,
new object[] { 2,3 });
}

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

thanks

steph


Nov 27 '06 #1
6 16508
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
Nov 27 '06 #2
>how do... call a method of another running exe...
You have to use Remoting or some other kind of inter-process
communication.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 27 '06 #3
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.
On Mon, 27 Nov 2006 18:37:46 +0100, "Steph" <pi**@pipo.comwrote:
>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("WindowsApplication1TE ST");
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
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 27 '06 #4
Steph wrote:
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("WindowsApplication1TES T");
foreach (Process TempProcess in NewProcessList2)
{
// BUG :
TempProcess.MainModule.GetType().GetMethod("math_a dd").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.
Nov 28 '06 #5
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" <ts****@gmail.coma écrit dans le message de news:
e%****************@TK2MSFTNGP02.phx.gbl...
Steph wrote:
>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("WindowsApplication1TE ST");
foreach (Process TempProcess in NewProcessList2)
{
// BUG :
TempProcess.MainModule.GetType().GetMethod("math_a dd").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.

Nov 28 '06 #6
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

"Steph" <pi**@pipo.comwrote in message
news:45***********************@news.orange.fr...
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

Nov 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Titus Cheung | last post by:
Hello, I want to write some code such that it'll update (ie insert, delete, etc) some data to/from a mySQL database whenever a user hit an HTML form button (ie Submit). Now what I find annoying...
0
by: Eugene Safrankow | last post by:
Hello All! I've encountered with the error when I call a method of dependency library (written in managed VC++) from Smart Client placed on a web page. In general, I make a call to the Windows...
26
by: Paul | last post by:
public class A { public A () { // here I would like to call the second version of _ctor, how to accomplish this ? } public A (int a, int b, int c) {
5
by: Wilfried Mestdagh | last post by:
Hi, I want to overload a constructor of a class. But I want to call the other one from the second if called. I explain with code because of my english: public class XMLConfig { public...
13
by: jac | last post by:
Hae, I have a windows form with a ComboBox an other things. On that combobox I have an eventhandler on de selectedindexchanged. But somewhere in my code want to do excecute the same code that...
3
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with...
46
by: Steven T. Hatton | last post by:
I just read §2.11.3 of D&E, and I have to say, I'm quite puzzled by what it says. http://java.sun.com/docs/books/tutorial/essential/concurrency/syncrgb.html <shrug> -- NOUN:1. Money or...
2
by: mahi543 | last post by:
how can we call one class main method from another class main method? i tried but i got an idea for method we can call one method from another method
1
by: Mike | last post by:
I have an web page (page1.aspx) that has a method in the code behind that I want to call from another page. Is this possible to do? The method resides in the page1.aspx.cs file, its a public...
6
by: Christopher | last post by:
Its been awhile and I am rusty. Can the constructor of my class call another method in the same class if that other method does not change any member data? I want to simply have a seperate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.