Question

Hi we have a c++ project (library) which has to exposed to .net languages or may be other languages (old vb for example but this is not very important). Two options are write COM wrapper for the project or managed c++ wrapper. Which one to choose?

One great advantage, for example, of using manged c++ is using .net collections classes to pass as a parameters instead of enormous complexity of collections in COM.

Was it helpful?

Solution

If you're COM collections are enormously complex, you may want to rethink how you approach COM collection management. Totally different issue there, but that being said...

Your mention of old-VB not being very important is more critical to your answer than you may think. Old VB doesn't speak .NET, but it does speak COM very well. If you foresee having to go that road, that is a major push to the COM side.

I'm not a fan-per'se of managed C++ only because it is about the most non-portable, hard-to-manage, hard to read dialect of the language you'll likely ever encounter. However, if the core code in your library is simple enough, you could probably get it up and running in managed C++ with reasonable effort. The more dynamic the library is, the harder it will be to port to .NET management. However...

Once it is there, a COM wrapper can get you back to your COM clients like legacy VB without too many problems provided you took wise choices when doing the port and kept things easily wrappable along the way.

Thats about the most round-about way I can say (with great pain) managed C++ is likely your best option, but I would seriously gel on it before throwing down that gauntlet.

OTHER TIPS

The term "COM wrapper" doesn't make much sense. If want to create a COM class, there's no reason why you should first create a vanilla C++ class and then create a COM class that wraps it and mimics it. That's one advantage of COM over managed C++: in managed C++, you DO have to create a vanilla C++ class (for unmanaged clients, unless you don't have any) and a managed wrapper class for it (for managed clients).

In my opinion, the deciding factors for when you should use COM or managed C++ for interop are easy:

Use COM if you want to create a completely new unmanaged class (not a wrapper) that can be consumed by clients in any language.

Use managed C++ if want to create a completely new class (not a wrapper) in which you mix a lot of managed and unmanaged code.

So you see, the word "wrapper" shouldn't come up anywhere in your design. Wrappers suck :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top