5

I'm at a bit of a loose end here, I'll do my best to explain and I hope it all makes sense.

I'm trying to find a way to wrap a C++ Console App in a C# Class so I can use the C++ App as a library within the C# app rather than triggering the C++ exe and providing a command to it.

The reason why I wish to do it this way is for maintainability, so I can make changes to the C++ app without affecting the C# App.

I've been looking at tutorials and stack overflow to see if's its possible, but for someone with learning difficulties, I'm struggling to find the right path to take as I'm seeing conflicting info.

Any help would be greatly appreciated, Thanks in advance

Comments
  • 2
    I'd say DllMain is your friend
  • 1
    DllImport and MarshalAs to interop, but considering maintainability, it will be a pain in the ass.
    My suggestion is to load both projects as a single solution in visual studio, then use the magical managed mode for cpp. It's truly a whole other world when .net meets binaries, have fun! 😅
  • 0
    Not sure I understand… do you want to use functions/methods exported by the C++ app? If so, DllImport is your friend.

    Or do you want to run the C++ app, potentially passing input to it, and return its output to the C# app? Spawn a process, attach TextReader objects as stdin/stdout/stderr, and use the usual .NET functionality to write to/read from them.

    I'll leave investigating the details as an exercise to you.
  • 0
    @SomeNone the second one is exactly what I want to do, however everything that I’ve read is telling me to reference the exe file rather than linking to a library, unless I’m missing something

    @myss can I still pass command line arguments through to a DLL?

    @HitWRight are you able to pass through a link to some documentation, I’ve not been able to find anything
  • 0
    @err-occured by what you wrote to @SomeNone, that is what is suggested, add the project/exe as a reference.
    https://docs.microsoft.com/en-us/...
    The link is for DllImport. There are a lot of specifics on how dynamic linking works, would suggest to read on that also
Add Comment