Microsoft KB Archive/260574

= How To OL2000: Work with Linked Contacts of Outlook Items Using the Outlook Object Mode - Visual C++ =

Article ID: 260574

Article Last Modified on 9/13/2006

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Visual C++ 6.0 Service Pack 5

-



This article was previously published under Q260574



SUMMARY
This article demonstrates how to work with linked contact items that are associated with task and journal items by using the Outlook Object Model. The process is enhanced in Outlook 2000 by the addition of the Links collection.

For additional information on using smart pointers, click the article number below to view the article in the Microsoft Knowledge Base:

259298 How To Use Microsoft Outlook Object Model From Visual C++ Through an #IMPORT Statement



MORE INFORMATION
Outlook 2000 Object Library

The following code sample demonstrates different ways to work with linked ContactItem objects for Outlook 2000. void AddLinkedContactToTask { _ApplicationPtr spOutlook(&quot;Outlook.Application&quot;); _NameSpacePtr spNameSpace = spOutlook->GetNamespace(&quot;MAPI&quot;); MAPIFolderPtr spTasksFolder; _ItemsPtr spTasks; _TaskItemPtr spTask; MAPIFolderPtr spContactsFolder; _ItemsPtr spContacts; _ContactItemPtr spContact; LinksPtr spLinks; LinkPtr spLink;

// Get first taskitem from default tasks folder. spTasksFolder = spNameSpace->GetDefaultFolder(olFolderTasks); spTasks = spTasksFolder->Items; spTask = spTasks->GetFirst; // Add new linked contact by adding a link object. // Get first contact from default contacts folder. spContactsFolder = spNameSpace->GetDefaultFolder(olFolderContacts); spContacts = spContactsFolder->Items; spContact = spContacts->Item((long)1); // Get links collection and add contact. spLinks = spTask->GetLinks; spLink = spLinks->Add(spContact); spTask->Save; spTask->Close(olSave); OutputDebugString((LPCTSTR)spTask->GetContactNames); OutputDebugString((LPCTSTR)spTask->GetSubject); spLinks = spTask->GetLinks; // Loop through links collection. for (long j = 1; j < spLinks->GetCount; j ++) { spLink = spLinks->Item(j); // Check link type before getting item. if (spLink->GetType == olContactItem) { spContact = spLink->GetItem; if (spContact) { OutputDebugString((LPCTSTR)spContact->GetFullName); spContact = NULL; }   }    spLink = NULL; } spContact = NULL; spContacts = NULL; spContactsFolder = NULL; spLinks = NULL; spTask = NULL; spTasks = NULL; spTasksFolder = NULL; spNameSpace = NULL; spOutlook = NULL; } Outlook 97 and Outlook 98 Object Library

Use the Recipients collection of task and journal items to add new linked contacts.

Use the ContactNames property to retrieve a delimited list of the linked contacts display names.

NOTE: When you use Outlook 2000, items that were created with Outlook 97 or Outlook 98 may contain valid data in the Recipients collection and ContactNames property; however, these properties do not contain valid data in items that are created with Outlook 2000.

Keywords: kbhowto kboutlookobj kbmsg KB260574

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.