Tech Support > Microsoft Windows > Development Resources > Using C++ in Shared Library/Dll
Using C++ in Shared Library/Dll
Posted by Olga Wepper on November 26th, 2007


Hello everyone!

I'm searching for informations about creating a shared library with c++
classes in it. Using a factory class which resides in the dll is a possible
(and maybe the only) way to create objects from within the dll.
But how can the client (of the dll) use such objects? Is it possible to use
several class-member var's or functions in the client?

It's also a question of what compiler is used. What would be the most
portable way to implement a simple dll which provides c++ objects? (Do i
have to ship some compiler specific library code to handle this?)

Many questions and i've searched through google but maybe i've used the
wrong keywords.
Thanks
Olga

Posted by Markus Schaaf on November 29th, 2007


Olga Wepper wrote

To cut a long story short: If you are targetting a particular
compiler, refer to that compiler's documentation on how to create
a C++ DLL. With e.g. Visual-Studio this boils down to choosing
the right project type. But: most probably this DLL will be
useful with that particular compiler only, i.e. same vendor and
same version. If you want a more portable library with an
object-like interface, consider using COM/ActiveX.

Posted by Grzegorz Wróbel on November 29th, 2007


Olga Wepper wrote:
Same way, but you will need to provide a header file with class
definition and declaration of its methods. Dll should contain only
implementation of the methods) and the accompanying .lib file (which
tells the linker how to use the functions in the dll) .

That depends. You can ship the accompanying lib file, and this file will
be compiler specific - ie most likely to be used only with the same
compiler.

It is possible to use the dll without the .lib. This is fully portable
way, but it requires to "manually" map the functions to the code in the
dll using LoadLibrary() and GetProcAddress().


--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D


Similar Posts