Reputation: 14413
I have a plugin written for a C++ program (as a .dll). The interface this .dll relies on is something like the following:
class Platform
{
virtual bool callSomeFunc() = 0;
//etc.
}
The .dll provides the platform with an object through an extern "C"
function. Pretty standard. The .dll can interact with the platform via an object of a class implementing the above interface. Pretty standard I guess.
Now we have a need to write the platform in C#. Ideally without rewriting the plugin because we have most of our code in plugin. Is there a way to go about this? (Something like passing a C# object for the Platform
object the .dll expects?)
Upvotes: 0
Views: 144
Reputation: 612964
If you wish to implement an object in the C# code that the unmanaged code can use, then you can no longer use a C++ class. Only C++ code can create C++ classes. C# code cannot.
The obvious thing to do is to use COM for your interop. The C# code can both implement and consume COM objects.
Upvotes: 1