5

I am writing a program that utilises a c# sdk. The functionality of this program will be used in a larger program written in c++ using QtCreator. I would like to create a c# dll to interact with the sdk and then consume this in the c++ program. Has anyone done this before and can point me in the right direction.

Many thanks.

1 Answers1

4

You can, I do this regularly at work. You can consume C# from C++ using COM and Interop. Worth noting now that this is all windows only.

If you've not used COM from C++ before you are in for a nasty surprise. It's fairly unpleasant.

This is a very big topic, so I can't really cover it in a post, but if you want to learn more, I'd look here for starting on the C++ side:

COM(C++) programming tutorials?

I'd recommend using ATL to make your COM life a lot easier.

EDIT: Actually I didn't know this, but Qt has COM support, so you'd be much better off using that - Have a look at https://doc.qt.io/qt-5.10/activeqt-index.html

Google around for the C# side, but it's mostly about using the ComVisible and Guid attributes on your classes to make them COM ready and then registering them using regasm.exe (Part of the .NET Framework).

Richard Matheson
  • 1,095
  • 11
  • 22