Boost logo

Boost :

From: Stefan Seefeld (sseefeld_at_[hidden])
Date: 2004-12-08 11:29:24


> > 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?
>
> Either omit the extern "C" or, if you must use a C-style
> interface, do this:
>
> extern "C" Interface* DLLCreate()
> {
> return new InterfaceImpl;
> }
>
> extern "C" void DLLDestroy( Interface* p )
> {
> delete p;
> }
>
> and then construct an InterfacePtr( DLLCreate(), DLLDestroy
> ). You'll need a
> public virtual destructor in this case, though.

When writing plugins under linux (i.e. with 'dlopen' etc.),
I believe I have already used a function returning a std::auto_ptr as
entry point for the loader. What is wrong with that ? Is your advice
above simply due to a limitation with MSVC ?

Regards,
                Stefan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk