Hi,
I wonder if anyone can give me some advices for this
problem.
I have been working on some program to interface with some
devices and I would like to use the OO model to interface
with different devices with different dll.
I tried to seperate the design into 3 layers:
/* BaseDevice .h */
class EXPORT_DLL_PREFIX BaseDevice{
public:
BaseDevice(){}
~BaseDevice(){}
virtual void DeviceCallA()=0;
};
typedef BaseDevice * (CALLBACK* BASEDEVICE_GET_INSTANCE)();
/* Inherited Device class A DeviceA.cpp */
#include <BaseDevice.h>
#static BaseDevice instance = NULL;
class EXPORT_DLL_PREFIX DeviceA: BaseDevice
{
public:
DeviceA() {// do something}
~DeviceA() {// do something }
DeviceCallA()
{
// Do the actual work here...
}
};
BaseDevice * getInstance()
{
....
instance = new DeviceA();
return instance;
}
/* upper interface layer upper.cpp */
...
static BASE_DEVICE_GET_INSTANCE getInstance;
....
BaseDevice * device;
.....
getInstance = (BASE_DEVICE_GET_INSTANCE )GetProcAddress(
modHandle, _T( "getInstance" ) );
// link to the (DeviceA.dll) and get the instance...
device = getInstance();
device -> DeviceCallA();
..
Turn out it works. However, if I would like to add
another method to the BaseDevice.h for the new support
device, problems comes up. Any previous application which
was developed using DeviceA.dll will not run. I know that
it is due to the virtual table ordering when new methods
are added.
Are there any suggestion to this problem that adding new
methods will not affect previously developed applications
which used link to the previous version of the dll
implementing the previous version of the abstract class?
Thanks!
Kenric