Question

Given a DLL with the following classes :

#define DLLAPI __declspec(...)

class DLLAPI Base
{
    public:
    virtual void B();
};

class Derived : public Base
{
    public:
    virtual void B();
    virtual void D();
};

Will my "Derived" class be visible outside of the dll even if the "DLLAPI" keyword is not applied to the class definition (at least, not directly)?

Is the "D()" function visible to?

Thanks

Was it helpful?

Solution

class Derived won't be exported by your DLL. Classes don't inherit exporting. Add DLLAPI to that too.

Note too that class members default to private accessibility, so none of your methods should be accessible. However, I do see Base::B() being exported in my test. The C++ header in the DLL-using code would flag the error, but I wonder if you tweaked the header there, if you could fool it.

Anyway, if you did instantiate a Derived inside your DLL (via another entry point), the virtual table should still work, so if you did:

Base* b = getTheDerived(); b->B();

you'd invoke Derived::B().

OTHER TIPS

You can find out from a Visual Studio command shell by typing

link /dump /exports <yourdll>

If they are exported, you will see "decorated names" for the functions. To see what they are in human readable format, copy-paste one and do

undname <decorated name>

No, Derived will not be visible outside of the DLL. In order to export the derived class, you would have to apply the DLLAPI macro to derived classes as well.

You have to make both the base and derived classes exportable,

http://msdn.microsoft.com/en-us/library/81h27t8c.aspx

All base classes of an exportable class must be exportable. If not, a compiler 
warning is generated.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top