Here is my golden rule regarding DLL and C ++.
The internal DLL code can be written in C ++, but only C functions should be exported from the DLL. But you can have "factory" functions that return C ++ interface pointers
It just gets confused trying to export each method from each class from a DLL. As for components and interfaces.
DLL, Windows. COM - . COM - . COM-DLL, . ATL (CComObjectRootEx ), . ++ COM. , COM- "" singleton.
, , . ( COM-, - DLL, , IDispatch - ).
, COM, , DLL COM.
class IMySingleton
{
public:
virtual int DoSomething()=0;
virtual int DoSomethingElse()=0;
virtual void AddRef()=0;
virtual void Release()=0;
};
HRESULT GetMySingletonInstance(IMySingleton** ppMySingleton);
class CMySingleton : public IMySingleton
{
public:
int m_refcount;
static CMySingleton* s_pInstance;
static CMySingleton* GetInstance()
{
if (s_pInstance == NULL)
{
s_pInstance = new CMySingleton();
}
else
{
s_pInstance->AddRef();
}
return s_pInstance;
}
CMySingleton()
{
m_refcount = 1;
}
~CMySingleton()
{
}
int DoSomething()
{
return x;
}
int DoSomethingElse()
{
return y;
}
void AddRef() {m_refcount++;}
void Release()
{
m_refcount--;
if (m_refcount == 0)
{
s_pInstance = NULL;
delete this;
}
}
};
HRESULT GetMySingletonInstance(IMySingleton** ppSingleton)
{
*ppSingleton = static_cast<IMySingleton*>(CMySingleton::GetInstance());
}
, singleton, GetMySingletonInstance. , singleton, Release() , .