1
votes

I need to build a C++ library to distribute among our customers. The library must be able to be accessed from a wide range of languages including VB6, C++, VB.net and C#.

I've being using ActiveX controls (ocx files) until now. But I wonder if there is a better kind of library (dll, etc.) that I can build. What do you recommend?

I'm limited to C++ as the library language, but you can mention other languages for reference to other developers.

P.S. Sorry if the question was already asked. I had some trouble finding a suitable title. Feel free to correct my English.

Edit: Seems like the best choice is either DLLs or OCX (i.e., COM), but I'm still having some doubts on which one will I choose. Which one is more suitable to modern languages (.NET for instance)? Which one would be easier to use from an end developer perspective?

4

4 Answers

3
votes

Almost every language has a way of loading dynamic libraries and accessing exported C functions from them.

There is nothing preventing you from using C++ inside the dll but for maximum portability, export only C functions. I have some more about this in this post.

3
votes

If you're looking at supporting both VB6 and .NET, you're pretty much stuck with exposing interfaces via COM, but at least that'll get you out of having to create more than one wrapper based on the language/runtime system you're trying to interact with.

1
votes

If there is any chance this will need to be ported to non windows platforms then a DLL / Shared library is your best choice as a COM object really isn't at all portable.

In addition you can call a DLL from almost any platform even if it requires you to write a wrapper of some kind. It's pretty easy to wrap a dll in a com object but if you make a native com object it's a lot harder to add a C style DLL API. Plus you might want to call it from java for example and it's much easier to write a JNI wrapper to call your DLL than get it working with COM in any kind of cross platform way.

Really it depends on what platforms you really need to call it from and how certain you can be that you won't get something out of the ordinary in future.

0
votes

To be callable from all those languages your only real option is going to be COM, without having to write wrappers where required (which would defeat the point)