Boost logo

Boost :

From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-12-08 10:31:33


is it possible to return a shared_ptr to an interface from a dl?. I
thought of the following what unfortunately doesn't work:

// Interface.h - exe project
class Interface
    vitrtual void f( void ) = 0;
    virtual void g( void ) = 0;

     ~Interface( void ) {}

typedef shared_ptr<Interface> InterfacePtr;
InterfacePtr Create( void )
    // Load a special create function from the dll

    return DLLCreate();

// InterfaceImpl.h - dll project
#include Interface
class InterfaceImpl : public Interface
    void f( void ) { /* ... */ };
    void g( void ) { /* ... */ };

    // No copy operations

extern "C" InterfacePtr DLLCreate( void )
    return InterfacePtr( new InterfaceImpl );

At the moment this code doesn't compile because VS7.1 complains that it
a function with extern "C" linkage can't return a shared_ptr<Interface>
instance. How could I implement the desired behavior?

Some other related questions regarding this topic:

1.) I link to the multithreaded C run-time dll - is this allowed? I read
in an older post that only static CRT linking is allowed.

2.) Does the above code - loading the factory from the DLL as well and
(hopefully) constructing the instance there - solve the boundary
problems? I read some articles regarding this issue, but to be honest I
haven't completly understood the problems that may occure in this case
so far.

Any help is greatly appreiciated..


Boost list run by bdawes at, gregod at, cpdaniel at, john at