IMessengerContacts::Item

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.

Syntax

HRESULT Item(
   [in] LONG Index,
   [out,
   retval] IDispatch** ppMContact
);

Parameters

  • 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
    Success.
  • RPC_X_NULL_REF_POINTER
    ppMContact is a null pointer.
  • E_FAIL
    The invalid collection or index number provided exceeds the length of the collection.
  • E_INVALIDARG
    Index is not a positive integer.

Remarks

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.

Example

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)
{
   try
   {
      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());
   }
}

Requirements

  • 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
    Msgrua.idl

See Also

Reference

IMessengerContact