2

I have a C++ DLL that needs to call a function (pass a value, return a value) in a C# class library.

Is my only option to give the C# DLL a COM interface and call it from C++ with IDispatch?

Is this the best method?

Jason
  • 16,739
  • 23
  • 87
  • 137

4 Answers4

6

Couple of options available for you here

  1. Use a mixed mode C++/CLI assembly as a bridge between the C++ and C# DLL
  2. Use the a COM bridge by exposing several of the key C# types as COM objects. This can then be accessed via the C++ code by normal COM semantics
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
1

This project Creates dll exports for static methods in classes. You could then call a C# static method from unmanaged code.

Justin Dearing
  • 14,270
  • 22
  • 88
  • 161
0

One approach that would work would be to call it though COM. You can use the Regasm tool to create the COM wrapper.

Rob
  • 3,026
  • 4
  • 30
  • 32
0

It's not the only option.

You could also compile your C++ DLL as a managed DLL.

You could host your C# DLL as a service and remote into it.

rein
  • 32,967
  • 23
  • 82
  • 106