Vtable layout and binary compatibility

  • Thread starter Thread starter Niranjan Khanapurkar
  • Start date Start date
N

Niranjan Khanapurkar

Guest
//DLL code(Version 1)
class base
{
protected:
EXPORT_ATTRIBUTE virtual void disp1();
EXPORT_ATTRIBUTE virtual void disp2();
public:
EXPORT_ATTRIBUTE virtual void fun1();
EXPORT_ATTRIBUTE virtual void fun2();
};

class derived: public base
{
public:
EXPORT_ATTRIBUTE virtual void fun1();
EXPORT_ATTRIBUTE virtual void fun2();

};

//EXE code
int _tmain(int argc, _TCHAR* argv[])
{
base *bPtr = new derived;

bptr->fun1();
bptr->fun2();
}//Works fine

//Later i changed the DLL code:(Version 2)
class base
{
protected:
EXPORT_ATTRIBUTE virtual void disp1();
EXPORT_ATTRIBUTE virtual void disp2();
EXPORT_ATTRIBUTE virtual void disp3();//Added new virtual method
public:
EXPORT_ATTRIBUTE virtual void fun1();
EXPORT_ATTRIBUTE virtual void fun3();//Added new virtual method
EXPORT_ATTRIBUTE virtual void fun2();
};

class derived: public base
{
public:
EXPORT_ATTRIBUTE virtual void fun1();
EXPORT_ATTRIBUTE virtual void fun3();//In derived as well
EXPORT_ATTRIBUTE virtual void fun2();

};







And i have not recompiled the EXE code so its still referring to the first version of the DLL. But still this exe works fine with the version 2 DLL.

I heard that adding new virtual function in between other funtions in base will break the binary compatibility as the layout

of the vtable is changed in DLL and exe still referring to old vtable layout.

Could someone please help me to understand how this works without recompilation of the executable? I am using Visual studio 2013

for compilation.




Niranjan

Continue reading...
 
Back
Top