Platform SDK: Exchange 2000 Server

Count Property

[This is preliminary documentation and subject to change.]

Returns the number of Message objects contained in the collection.

[Visual Basic]
Property Count as Long
read-only
[C++]
HRESULT get_Count(long* pVal);
[IDL]
HRESULT [propget] Count([out,retval] long* pVal);

Remarks

The Count property returns the number of objects in the collection. The indexes for the objects in the collection range from 1 to Count.

The collection is not automatically updated when new messages arrive in the directory used to retrieve the Messages collection. Count only returns the number of Message objects currently in the collection, and not the number of messages that actually reside on the file system at any given time. To update the collection, you need to call IDropDirectory.GetMessages again and thus retrieve a new collection.

Example

[Visual Basic]
Dim iDropDir as New CDO.DropDirectory
Dim iMsgs as CDO.IMessages
Dim iMsg as CDO.Message
Dim i as Long
Dim C as Long
i = 1
Set iMsgs = iDropDir.GetMessages
C = iMsgs.Count
For i = 1 to C
  Set iMsg = iMsgs.Item(i)
  If iMsg.To = "someaddress" Then
   iMsgs.Delete i
  End If
Next i
[C++,IDL]
#import "d:\program files\common files\system\ado\msado15.dll" no_namespace raw_interfaces_only
#import <cdosys.dll> no_namespace raw_interfaces_only
#include <iostream.h>

void main(int argc, char* argv[])
{
  CoInitialize(NULL);

  IDropDirectory* pDropDir = NULL;
  IMessages* pMsgs         = NULL;
  IMessage* pMsg           = NULL;
 CoCreateInstance(
          __uuidof(DropDirectory),
          NULL,
          CLSCTX_SERVER,
          __uuidof(IDropDirectory),
          (void**)&pDropDir));

  pDropDir->GetMessages(L"",&pMsgs);
  long count = 0;
  pMsgs->get_Count(&count);
  cout << count << endl;
  for(long i = 1;i<=count;i++) {
      pMsgs->get_Item(i,pMsg));
      BSTR szTo;
      pMsg->get_To(&szTo);
      if(_bstr_t(szTo) == _bstr_t("someaddress"))
          pMsgs->Delete(_variant_t((long)i));
      SysFreeString(szTo);
   }

  CoUninitialize();
}