adding a contact(name) to a new created journal in visual c++

  • Thread starter Thread starter Martin Schroll
  • Start date Start date
M

Martin Schroll

hello there,

i have a problem with adding a contact to my new journal.
When i use JournalItem.SetContactNames(strContact);
the form doesn't show the contact name in the contact-box.
Now i have read that you must use "olItem.Links.Add" in vb. But i
don`t know how to do "oItem.Links.Add" in vc++, because there is no
Links-property on my JournalItem-object.

thanks for support
Martin
 
Now i have found a possible solution for this problem:


CString COutlookKontakte::OpenNewJournal(CString strLoggedUsername,
USERDATA UserArray[])
{
CString EntryIDResult="";
_Application olApp;
COleException error;

try{
// if it is already running, we'll use the same instance
if(!olApp.CreateDispatch("Outlook.Application", &error)){
CString str;
str.Format("CreateDispatch() failed w/error 0x%08lx", error.m_sc);
AfxMessageBox(str, MB_SETFOREGROUND);
return EntryIDResult;
}

// logon
_NameSpace olNs(olApp.GetNamespace("MAPI"));
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
olNs.Logon(covOptional, covOptional, covOptional, covOptional);

// open default outlook contacts folder
MAPIFolder myContactsFolder(olNs.GetDefaultFolder(10));
if(myContactsFolder==NULL){
AfxMessageBox("Could not find default contact
folder!",MB_ICONEXCLAMATION);
return EntryIDResult;
}

// get the items from the folder
_Items myItems(myContactsFolder.GetItems());
if(myItems==NULL){
AfxMessageBox("Unable to get contact items!", MB_ICONEXCLAMATION);
return EntryIDResult;
}

// get the right contact item
_ContactItem myContactItem(olApp.CreateItem(2));
CString strFind;
strFind.Format("[FirstName]=\"%s\" and [LastName]=\"%s\"",
UserArray[0].Vorname, UserArray[0].Nachname);
if(!(myContactItem=myItems.Find(strFind))){
AfxMessageBox(APP->m_rl.Load(IDS_MSGBOX_DS), MB_ICONEXCLAMATION);
return EntryIDResult;
}

// create and open a new journal
_JournalItem JournalItem(olApp.CreateItem(4));
VARIANT vt;
vt.vt=VT_BOOL;
vt.boolVal=FALSE;
CString strBody=APP->m_rl.Load(IDS_STRING_ADV)+strLoggedUsername;
JournalItem.SetBody(strBody);
Links myLinkCol=JournalItem.GetLinks();
myLinkCol.Add(myContactItem.m_lpDispatch);
JournalItem.StartTimer();
JournalItem.Save();
JournalItem.Display(vt);
EntryIDResult=JournalItem.GetEntryID();
olNs.Logoff();
}
catch(COleException *e){
e->Delete();
AfxMessageBox(APP->m_rl.Load(IDS_MSGBOX_ERROR) + "
'OpenNewJournal'!", MB_ICONERROR);
return EntryIDResult;
}
return EntryIDResult;
}
 
Back
Top