user1040229
user1040229

Reputation: 501

Should I create a C++/CLI wrapper DLL for an unmanaged C++ DLL?

I have been provided with an unmanaged C++ DLL that contains several classes.

I need to be able to use some of these classes in C#. Based on my research so far, it sounds like I need to create a C++/CLI wrapper DLL that would handle converting between managed and unmanaged types. I have seen some examples where someone would basically create a C++/CLI version of each class and it would contain an instance of the unmanaged C++ type. What is the best way to implement what I am trying to do here? There are maybe 10-15 classes provided in the unmanaged DLL. Right now I only need to use a few of them but may need to use more in the future. Thanks!

Upvotes: 3

Views: 1015

Answers (1)

Alex F
Alex F

Reputation: 43321

Yes, you need to create C++/CLI wrapper for this library, and use unmanaged classes internally in this wrapper. For unmanaged library which exposes C-style API, there is also PInvoke option, but it doesn't work for C++ classes.

You can also think about making COM wrapper, it you want to use this library both in native COM clients and .NET. But making C++/CLI wrapper is more simple task, I think.

Upvotes: 5

Related Questions