Link to home
Start Free TrialLog in
Avatar of Sukhani
SukhaniFlag for India

asked on

communicate between two .net programs

Hello Everyone,

I have a Windows Form Application which has been developed in .net 3.5. The language used to develop is VB.NET. It a charting program and shows stock market charts to users.

Now I have made another program in vb.net (same .net version) and I want this program to interact with the one I made before. The new program is like a small scripting language. So for example: if i run a script then its output should be reflected in the other program. How can the two programs communicate ? Both will be running on same systems. No remote stuff.

Plus I have several functions which are written in first program. Is it possible for the other program which is an .exe also to call the functions of the other one if I make sub/function public or something. The reason is we can calls functions or subs if we include a dll. But can one exe calls functions/sub of another exe (if both program are in .net).

I will be glad if anyone can help me out.

Thank You,

Cheers,
Saurabh
Avatar of el_aristo
el_aristo

if you dont have the .exe s codes and if they didnt configurated for input parameters , you cannot do any modifications like this ,
if you have the code you can reference the dlls
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sukhani

ASKER

While I look into named pipes and remoting, is there a way my one exe can access functions/subs in other one. I have code for both. Putting code in Dll wont be easy as they are written in program and I would need to make a lot of changes. Or can I make a new dll which I can include in my first program and pass my exe to dll by reference and then it can access functions.
As I said, you can compile the common code into a DLL and use that in both EXEs.
Sorry I did not read your full comment.

Making changes to move the code to DLL will save you from a lot of headache in future when you have same code in multiple places and you need to debug/change the code.
Avatar of Sukhani

ASKER

Compiling common code into a dll will be a lot of work as I have a lot of code and they are written in such a way that I will have to make a lot of changes.
Avatar of Sukhani

ASKER

While I check if I can compile common code into dll, is there any alternative. Can I write a dll which I can include in my first program and it can call functions in my exe program.
You might try exposing your public methods to COM and using Interop to automate, much as you would in an Office Application.

Here's an article that might give you some ideas: http://www.codeproject.com/KB/COM/nettocom.aspx
is there a way my one exe can access functions/subs in other one.
You can add a reference from one .exe to the other, much like using a DLL. The "referenced" .exe will work just like a DLL would, so it won't be "running" on its own; it will effectively be treated like a library of functions.
Avatar of Sukhani

ASKER

I tried the .net named pipe example which was given in msdn, it didnt seem to work the way I wanted.

Is there a way to my exe or dll can interact with my another exe and pass arrays and get value. Possibly using WCF or something easier. Can anyone give an example please ?
>Can anyone give an example please ?
You question is not about how to show a message box to which we can show the example with

Messagebox.Show("your message", "title", ...)

The question is generic and huge. You have many options. If you take the WCF route, it would be useful in future as well.
Avatar of Sukhani

ASKER

Well by example I mean a small code or so that shows how to do basic communication between two programs. For e.g. palpatin suggested that .net remoting is relatively easy. So a small code project that shows basic stuff. I can then expand or experiment on it.

If I can call function/sub in my exe then it will be useful. I dunno if .net remoting will allow that. WCF is complex I guess.
.NET remoting allows to make an object REMOTE so that you can call its functions from other EXEs. But you may have to rewrite your code. I would not be able to do a sample project (got plenty of my own to do). May be someone else has something to offer.
Avatar of Sukhani

ASKER

Let me try my hand in .net remoting and wcf.

Though what I did right now was create a sample exe with a public function. Include that exe in a dll and call its function. Though it worked but I think if the exe is running then it won't call the running exe's function. It will make a copy and call like a non running program. Am I right?
I think Yes. Calling a function in an exe from a DLL is the opposite of what is usually done though.
Avatar of Sukhani

ASKER

I was able to write code in vb.net that uses WCF and creates 2 servers so that 2 programs can independently exchange information/data. The server has to be on at all times though. I hope that does not create any load.
I think its initiated by user request so there should not be any load.
Avatar of Sukhani

ASKER

Actually its not like that. I want communication both ways in the two exe. So when the exe start I create server in both and client in both. Whenever one exe gets request it responds. This way servers are running at all times. So is this okay ?
I dont see any problem with that.
Avatar of Sukhani

ASKER

Here when we use http://localhost:8001. The 8001 or 8000, this has to be unique right. This is port, so what numbers are generally used.
Its totally random. Preferably use a number that has less chances of being repeated. Such as 6721