Re: member variables scope in atl com dll...
Hi Igor,
Thank you for your prompt response. I am sending below code snippet.
m_objDatabase is null when I am calling UseDatabase funnction. I would like
to use
m_objDatabase without static.
How? Please suggest me.
class ATL_NO_VTABLE CMyTest :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CMyTest, &CLSID_MyTest>,
public IDispatchImpl<IMyTest, &IID_IMyTest, &LIBID_MyTest1Lib>
{
public:
CMyTest()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_MyTest)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CMyTest)
COM_INTERFACE_ENTRY(IMyTest)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
// IMyTest
public:
STDMETHOD(GetRawData)(UINT SeqId, BSTR* RawData,INT* BlockLen);
STDMETHOD(OpenDatabaseAndGetFileInfo)(UINT nFileVersion);
STDMETHOD(FileRestore)(BSTR* UserName, BSTR* EncryptionPassword, BSTR*
FilePath);
private:
CMyDatabase m_objDatabase;
CString m_userName;
CString m_strFilePath;
}
STDMETHODIMP CMyTest::OpenDatabase(BSTR* username)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
m_userName = *username;
// TODO: Add your implementation code here
m_objDatabase= new CMyDatabase();
if(!m_objDatabase->OpenDataBase(m_userName))
return S_FALSE;
return S_OK;
}
//here m_objDatabase is getting null. I want to use m_objDatabase in this
function and already created in Opendatabase funcion.
STDMETHODIMP CMyTest::UseDatabase()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
if (m_objDatabase != NULL)
{
m_objDatabase->GetInfo();
}
else
{
MessageBox("failed...");
}
}
Thanks & Regards,
John.
"Igor Tandetnik" wrote:
John <John@discussions.microsoft.com> wrote:
I have developed atl com dll. It IMyTest interface and it is
implemented on CMyTest class. Object of CMyDatabase is the member
variable of CMyTest class.
IMyTest has three fuctions which are : 1. OpenDatabase, 2.
UseDatabase and
3. CloseDatabase.
In client side, OpenDatabase got succeded. But, application is getting
crash when UseDatabase function called. The object of CMyDatabase is
null in UserDatabase function. Any solution is there for this?
The code you show is fine. The problem must be in the code you don't
show. Show the declaration of CMyTest class, and how CMyDatabase member
is declared. Show the code in OpenDatabase and UseDatabase. Show the
exact line were the crash occurs.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925