views:

407

answers:

3

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

+1  A: 

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>
Drew Hoskins
+1  A: 

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.

Dan Shield
+3  A: 

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().