Outlook : error on putSubject( );

C

cyan21

hello,

I have got en error when I try to set a subject to an appointment.

CComPtr<Outlook::_AppointmentItem> appt;
_bstr_t titre("something");
BSTR tmp;
tmp = titre.copy();
appt->put_Subject(tmp);


the error occured when I made : appt->put_Subject(tmp); and the
debugger stops here :
// atlcomcli.h
_NoAddRefReleaseOnCComPtr<T>* operator->() const throw()
{
ATLASSERT(p!=NULL); // p is null
return (_NoAddRefReleaseOnCComPtr<T>*)p;
}

could someone explain me this error ?

thanks in advance.

yann
nb : I also tried the method PutSubject(_bstr_t subject) but at the
same error occured.
 
G

Guest

Actualy code you provided does not have real appointment.
You should create it first.


WBR
Henry

"cyan21" пишет:
 
C

cyan21

thanks, I managed to do it.

But now I ve got a problem to access datas contained in a
CComPtr<Outook :: MailItem>
For instance, I want to get the email's receiver in a method, but an
error occurs when I try to access it.
Moreover, when I try to access from another method, it works fine.


here is my code :

STDMETHODIMP COutlookEvents::ListenMail(void)
{

HRESULT hr;
CComPtr<Outlook::_NameSpace> namesp;
COleVariant v1;
v1.iVal = 0;
v1.vt = VT_I4;

/// connection to outlook
hr = olapp.CoCreateInstance(__uuidof(Outlook::Application), NULL,
CLSCTX_SERVER);
namesp = olapp->GetNamespace("MAPI");

/// create object
olapp->raw_CreateItem(Outlook::blush:lMailItem, &pDisp);
mail = pDisp;
mail->Display(v1);

......
}

STDMETHODIMP COutlookEvents::CopyEmail(IDispatch** item)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

*item = mail;

_bstr_t field;

field = mail->GetTo(); // ERROR
CString tmp;
tmp.Format(_T("%s"), (LPCTSTR)field);
MessageBox(NULL,tmp,"test",0);
return S_OK;
}


void __stdcall COutlookEvents::OnItemSend(IDispatch* Item)
{
MessageBox(NULL,"ok","OnItemSend",0);

_bstr_t field = mail->GetTo(); // OK I ve got the
address
CString tmp;
tmp.Format(_T("%s"), (LPCTSTR)field);
MessageBox(NULL,tmp,"handler",0);

}



message error :exception: _com_error

In the code : msoutl.tli

#pragma implementation_key(1043)
inline _bstr_t Outlook::_MailItem::GetTo ( ) {
BSTR _result = 0;
HRESULT _hr = get_To(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _bstr_t(_result, false); // _result 0x00000000 <Ptr>
incorrect

}


I made the same thing with appointment and it works fine but I really
don't understand why it can't with emails.

I hope someone could resolve my problem

thanks in advance

yann
 
C

cyan21

it seems the error come from the button Send.
I don't know why but when I push "Save" and "Close" button, it works
but when I push "Send" button it crashed.
It's strange because"Send" button fired "write" and "close" events.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top