This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Retrieves a specific contact by index. Not scriptable.


   [in] LONG Index,
   retval] IDispatch** ppMContact


  • Index
    [in] LONG that specifies the index of the desired IMessengerContacts object in the collection.
  • ppMContact
    [out, retval] Address of a pointer to an IDispatch interface on an IMessengerContacts object requested with Index. The object can now be accessed through the IMessengerContacts interface.

Return Value

Returns one of the following values. For managed code applications, these return values are received in the form of a COMException.

  • S_OK
    ppMContact is a null pointer.
  • E_FAIL
    The invalid collection or index number provided exceeds the length of the collection.
    Index is not a positive integer.


If you know the sign-in name for a user, you can get the IMessengerContact object by creating an object for it explicitly by calling the IMessenger::GetContact method. Even if that contact is already present in a list, the same pointer is returned (as it would have been by retrieving that object from an existing collection). Using the Item method, you can retrieve a contact from the collection based on that contact's position in the collection.


The example code instantiates and fills a collection of IMessengerContact objects by querying the IMessenger::MyContacts property of communicator. If there are contacts in the contact collection, the first contact in the collection is retrieved with the Item method to instantiate an IMessengerContact object. Finally, the friendly name of the contact is displayed on the application console window.

IMessengerContacts messengerContacts = (IMessengerContacts)communicator.MyContacts;
if (messengerContacts.Count > 0 && messengerContacts != null)
      IMessengerContact thisContact = (IMessengerContact)messengerContacts.Item(0);
      Console.WriteLine("Contact 1 Friendly Name: " + thisContact.FriendlyName);
    catch (COMException CE)
       Console.WriteLine("Contacts Item COM exception: " + CE.ErrorCode.ToString());


  • Client
    Requires Microsoft DirectX 9.0, C Runtime libraries (msvcm80.dll) on Microsoft Windows© Vista, Microsoft Windows XP Service Pack 1 (SP1) or later, or Microsoft Windows 2000 with Service Pack 4 (SP4). Any Communicator-imposed restrictions apply. .
  • Server
    Requires Microsoft Office Communications Server 2007, AV MCU (for Media Support), Media Relay (for NAT/Firewall traversal) on Microsoft Office Communications Server 2007.
  • Product
    Microsoft Office Communicator 2007 Automation API
  • IDL file

See Also