Hello,

I'm curious to know whether it is possible to expose the functions of a C# application so that they could be used by another C# application in runtime.
The thing I am referring too is quite similiar(might even be the same) as using an API. I have searched on this topic briefly and someone suggested using TCP protocol to allow 2 applications to communicate, but I am looking for a way of directly accessing some of the functions of an application instead.
Any advice or references would be great.
Thanks

As long as the methods don't need the application to be running to work, then you simply put them in a public class, and make the methods public, then reference the .exe from the new app. and all its public classes and methods will be available to other applications.

Im not entirely sure this is what I am looking for, let me provide an example which might hopefully clarify my intentions:

Imagine that I have compiled an application called "library.exe" this library has a function called getBookReference(string bookName).
If I made this function public is there anyway I could access it from a completely different application? So for instance I could make another application called librarySearch.exe and somehow access getBookReference() from the library.exe application.

Hopefully this example provides a clearer picture of the task I am trying achieve(although you can ignore the whole library thing). I am aware this type of functionality is available through the COM but I'm sure I have read about .NET providing this type of application communication.

Thanks

Yes you can. That's what I explained before. Create a public class with a pubic method GetBookReference(string book) or whatever you want. Compile it. and start a new application. Click on references. Click new reference. and browse to the first exe. then use the GetBookReference(string book) method. That simple. Just try it

that is assuming that you are using Visual Studio 2008. I believe older versions of Visual studio limits you to .dll even then you can manually add a reference using compiler arguments.

I just tested it in Visual studio 2008 to verify that it works, and it does.

Wow, It just sounded too easy to be true. I'll give it a test tomorrow and get back to you. Thanks man

Yeah after testing this it appears to work fine. What about accessing methods of a running application? Is this something that can be achieve in .NET?

IDK about that one. COM works with running apps. but I'm afraid that's where my usefulness here looses speed. Sorry. Hope you find your answer.

Much appreciated, Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.