Platform SDK: CDO for Windows 2000

_NewEnum Property

The _NewEnum property returns an IEnumVARIANT interface on an object that can be used to enumerate the collection.

[Visual Basic]
(*Restricted from direct access. Used in For Each In constructs)
[C++]
HRESULT get__NewEnum(IUnknown** retval);
[IDL]
[propget, restricted, id(DISPID_NEWENUM)] 
HRESULT _NewEnum([out, retval] IUnknown** retval);

Parameters

retval
On return, an IEnumVARIANT object reference that can be used to enumerate the collection.

Remarks

The _NewEnum property is marked restricted in the Interface Definition Language (IDL) definition for the IMessages interface and is not shown in the Microsoft® Visual Basic® object browser. It is automatically used internally when you use the For Each In construct in Visual Basic.

Example

[Visual Basic]
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Set DropDir as New CDO.DropDirectory
Set Msgs = DropDir.GetMessages("c:\mymail")
For Each Msg in Msgs
 ' Process each message here
Next
[C++]
#import "c:\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()
{
  CoInitialize(NULL);
  IEnumVARIANT* pEnum = 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;

  pMsgs->get__NewEnum(&pUnk);
  pUnk->QueryInterface(__uuidof(IEnumVARIANT),(void**)&pEnum);

  ULONG cFetched = 0;
  VARIANT var;
  VariantInit(&var);
  while (1) {
    cFetched = 0;
    pEnum->Next(1,&var,&cFetched);
    cout << "fetched: " << cFetched << endl;
    if(cFetched == 0)
       break;
    IMessage* pMsg = NULL;

    var.pdispVal->QueryInterface(__uuidof(IMessage),(void**)&pMsg);
    var.pdispVal->Release();
    VariantClear(&var);
    BSTR to;
    pMsg->get_To(&to);
    cout << _bstr_t(to) << endl;
    SysFreeString(to);
    pMsg->Release();

  }
  CoUninitialize();
}