IFoo::~IFoo()
{
// must implement base class destructor
// even if its abstract
}
// Note: we declare the class here because no one outside needs to be concerned
// with it.
class CFooImpl : public IFoo
{
private:
CFoo m_Foo; // the real C++ class from the existing MSVC C++ DLL
public:
CFooImpl(int x);
virtual ~CFooImpl();
virtual int __stdcall DoSomething(int x);
};
CFooImpl::CFooImpl(int x)
: m_Foo(x)
{
}
int __stdcall CFooImpl::DoSomething(int x)
{
return m_Foo.DoSomething(x);
}
CFooImpl::~CFooImpl()
{
}
IFoo * __stdcall new_IFoo(int x)
{
return new CFooImpl(x);
}
void __stdcall delete_IFoo(IFoo *f)
{
delete f;
}
//test
#include "dll.h"
void bar()
{
int x = 10;
int y = 20;
int z;
IFoo *foo = new_IFoo(x);
z = foo->DoSomething(y);
delete_IFoo(foo);
}