Count Property (IMessages)
Topic Last Modified: 2009-07-27
Returns the number of Message objects contained in the collection. This property is read-only.
Applies To
Type Library
Microsoft CDO for Exchange 2000 Library
DLL Implemented In
CDOEX.DLL
Syntax
Property Count As Long
HRESULT get_Count(long* pVal);
Parameters
- pVal
Returns the value of the Count property as a reference to a long.
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 the IDropDirectory GetMessages Method again and retrieve a new collection.
Examples
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
#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();
}