Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__declspec(dllimport/dllexport) and inheritance

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

like image 928
Nicolas Avatar asked Aug 12 '09 18:08

Nicolas


2 Answers

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

like image 86
Peter Cardona Avatar answered Sep 24 '22 17:09

Peter Cardona


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>
like image 35
Drew Hoskins Avatar answered Sep 24 '22 17:09

Drew Hoskins