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;
}