tags:

views:

223

answers:

4

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?

A: 

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)

Rowland Shaw
+3  A: 

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.

Laserallan
the only disadvantage would be that it would not support VB6, right?
djeidot
Why not? VB6 can load "plain" dlls with exported C functions.
Nemanja Trifunovic
Honestly, I've never tried, but some googling gave me some hits. This one seems to apply to vb6:http://msdn.microsoft.com/en-us/library/aa231253(VS.60).aspx
Laserallan
+3  A: 

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.

Timo Geusch
+1  A: 

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.

John Burton
How can a DLL be used from any non-windows platform? I'm intrigued...
Roddy
In this case I'm not looking at non-Windows platforms, but yes, I see your point.
djeidot