10

I have a C# app, i want to call a function name for example SendChatMessage(string message, int userid) from my app.But this function belongs another running client/server based application on my computer. I couldn't find the way how i can do this.

I try to make this with Reflection library but failed. Hope someone help me about this.

Thanks for help.

Erdem Alkan
  • 157
  • 1
  • 2
  • 7
  • 3
    Do you control the source code in the other program, or do you want to inject the commands into the process? Then you might have to use DLL-injection to take "control" over the other application. – NoLifeKing Nov 15 '13 at 10:39
  • Do you own the other app? Is the other app designed to allow other processes to invoke methods? – Rob Nov 15 '13 at 10:40
  • 1
    possible duplicate of [Using c# to call a function from another process](http://stackoverflow.com/questions/15767482/using-c-sharp-to-call-a-function-from-another-process) – Yosi Dahari Nov 15 '13 at 10:41
  • other program 32bit client/server based directx application. I can't control source code. – Erdem Alkan Nov 15 '13 at 10:54

2 Answers2

17

Welcome to the world of Inter-process communication. There are many methods to do this, like named pipes, RPC, shared memory, etc.

In a nutshell, your program is running inside a process. The other program is running inside another process. It's like your father trying to asking something from the boy next-door. These processes can communicate with each other and invoke each other's methods, or use each other's data. But not arbitrarily or course. They need some common standard for communication.

Take a look at these questions:

What is the simplest method of inter-process communication between 2 C# processes?

What is the best choice for .NET inter-process communication?

What is the easiest way to do inter process communication in C#?

Community
  • 1
  • 1
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • 1
    Thank you for answer but this answer correct if i have control of the other process program code. But i havent control the source code of other program. – Erdem Alkan Nov 15 '13 at 10:59
1

If you have no control over the code within the target process, then it sounds like you need to use a means of DLL-injection to inject your code into it.

If the calling process does not need an acknowledgement or response; then injecting code that performs method invocation code may surface, but if a response is required then it is likely that you will need to implement some form of inter-process communication within the code being injected.

Jamie Pearcey
  • 345
  • 1
  • 10