Passing Data to .NET C # WPF Application / DLL

I have a .NET C # WPF application that I am trying to do in a single instance application using Mutex.

This .NET application is called by a C ++ based library using CreateProcessAsUser () and gets parameters through environment variables.

Subsequent instances will also be created by the C ++ DLL in the same way.

Subsequent instances must then pass their parameters to the first instance of the application before exiting.

The problem is what methods can be used in a .NET application so that subsequent instances can pass their data to the first instance of the .NET application? The simpler the better.

I've looked into some, but hope there are easier ways.

Things I've researched:

  • Named pipes
  • .NET Remoting
  • Windows messages (sending WM_COPYDATA to the first instance window)

Since I am just trying to pass 4 lines to the first instance, I try to avoid the above methods because they are somewhat overloaded for my problem.

The simplest thing I can imagine is exporting a function from a .NET application so that subsequent instances of the .NET application can simply call that function in the first instance of the .NET application and pass the data as parameters to the function. However, is this possible in .NET? I read that .NET EXE or DLL cannot export functions.

Thank!

+1


source to share


3 answers


The simplest I can think of is exporting a function from a .NET application and then subsequent instances can simply call that function and pass parameters to it.

This is not how it works. You are loading the .NET assembly in the calling process, rather than magically crossing the process boundary and talking to the child.



It's just that the parent has to open the child with redirected pipes using the Process class and have the child read the stdin using Console.Read *

+1


source


thanks for the answer, Paul!

I've added more detail to my question above, though, although I'm not sure if I understood my script correctly.



But as far as your answer is concerned, the parent .NET application will be a C ++ based DLL and all it will do is call the .NET application and specify its parameters. After that, the C ++ DLL will also exit after that, so I wouldn't want to add more behavior to it.

This way, data transfers will only occur between instances of .NET applications.

0


source


Since you are moving from .NET to .NET, I would recommend just making a WCF call. You can use a named pipe for transport between two .NET instances to expose a "service" (which will be shown by your first instance).

Subsequent instances will check for one instance, and if they find an instance already running, they can make a WCF call to the service started in the first instance and pass the data that way.

0


source







All Articles