0

I have a dot net core application and I have to get the response from the C++ application. Also send the response back to C++ also.

In simple terms,

C++ -> C#

C# -> C++

I have gone through many links and got to know we can use DllImport in the C# application to access the Cpp methods. But DllImport and Named Pipeline are both the same or different?

If it is different, I want to access the C++ methods in the CSharp application using the Named pipeline.

Please suggest any links and clarify my doubts.

Thanks!

Gokul Kumar
  • 389
  • 6
  • 16
  • 2
    These are very different things. And since you cannot replace one with another, then lets just talk about named pipes. For that you can start here: https://learn.microsoft.com/en-us/dotnet/standard/io/how-to-use-named-pipes-for-network-interprocess-communication Named pipes are similar to streams. You need to know the protocol used by your C++ app in order to use them correctly. – freakish Jul 04 '22 at 10:35
  • Is your C++ app setup to respond to a named pipe? If not are you prepared to do the work to set that up? Dllimport would be the usual way to do this. – john Jul 04 '22 at 10:46
  • 1
    There's different scenario depending on if you own the code of the C++ application or not. In the case of owning the C++ code you can also think to create a wrapper in C++/CLI which is able to write both managed and unmanged code. The simplier way to call a method of a C++ library is the DllImport one. Setting up a named pipeline on a C++ could be a very challenging task – Marco Beninca Jul 04 '22 at 10:56

1 Answers1

1

DllImport and named pipelines are completely different things. You could indeed use DllImport and declare static extern functions that match the signature of your (exported) C++ functions and call them from your C# application. See: https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke

Named pipelines are for sending data from one application (or module) to another, where you would have to do the serialization and deserialization and/or mapping to functions yourself.

If you just want to call C++ code from C# code, DllImport is the way to go.

Tohnmeister
  • 468
  • 1
  • 5
  • 14