Re: Sharing a smart pointer between threads
Something else interesting:
If I try to use the object as below, it works the first time through
the timer, but each subsequent time, I get an "Invalid pointer"
exception when I do GetString(). Does the smart pointer think it's
going out of scope when the message handler exits in the thread?
CMyApp::OnTimer()
{
//...
TRACE(_T("OnTimer::A\n"));
_bstr_t bstString = pParent->m_spObj->GetString();
TRACE(_T("OnTimer::String: %s\n"), bstString);
//....
}
-PaulH
PaulH wrote:
It's NULL. (which explains the invalid pointer exception...)
It is being successfully created because I use it in the thread that
creates it just fine. It's just getting nullified in the thread I'm
posting it to.
Maybe the problem is that I'm posting it from the timer callback of an
MMtimer. So, really it's being posted like this:
MyLib::IInterfacePtr m_spObj; //private member var
/*static*/ CMyApp::OnTimer(...,DWORD_PTR dwUser,...)
{
CMyApp *pParent = reinterpret_cast<CMyApp *>(dwUser);
pParent->m_dialog->PostMessage(DLG_UPDATE,
reinterpret_cast<WPARAM>(&pParent->m_spObj));
}
-PaulH
Brian Muth wrote:
The exception (from a try-catch(_com_error) block) is: "Invalid
Pointer".
And what is the value of the pointer? Are you sure the object was
successfully created in the first place?
Brian