I have a C++ dll (x.dll) which exports a class that uses a static instance of MSXML2::IXMLDOMDocument2*.
In X.dll
wrapper.h
class EXPORTEDCLASS wrapper
{
wrapper();
public:
// Some accessor methods.
private:
PIMPL* pImpl;
};
wrapper.cpp
class PIMPL
{
public:
PIMPL();
static MSXML2::IXMLDOMDocumentPtr m_pDomDocument;
static s_bInit;
static void initDomDocument();
};
PIMPL::PIMPL()
{
initDomDocument();
}
void PIMPL::initDomDocument()
{
if(!s_bInit)
{
hr = CoCreateInstance(CLSID_DOMDocument40,NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument2, (void**)&m_pDomDocument);
m_pDomDocument->load(strFileName);
s_bInit = true;
}
}
wrapper::wrapper()
{
pImpl = new PIMPL();
}
m_pDomDocument is not released anywhere. But at some places it is only assigned to some local Smart pointers and they too are not explicitely released.
In the application the first call to the wrapper comes from DllMain of some other dll
This time the m_pDomDocument pointer is created and as such all the calls to the wrapper succeed.
When the next call comes which also happens to be from DllMain of some other dll, I find that s_bInit is true so I dont construct this object again.
But this time somehow m_pDomDocument is invalid. (Its value is same as for the first call but its vptr is invalid)
Can anybody tell me what might be going wrong here?