BOOL CMAPIEx::GetContents(LPMAPIFOLDER pFolder) {
    if (!pFolder) {
        pFolder = m_pFolder;
        if (!pFolder) return FALSE;
    }
    RELEASE(m_pContents);
    if (pFolder->GetContentsTable(CMAPIEx::cm_nMAPICode, &m_pContents) != S_OK) return FALSE;

    const int nProperties = MESSAGE_COLS;
    SizedSPropTagArray(nProperties, Columns) = { nProperties, { PR_MESSAGE_FLAGS, PR_ENTRYID } };
    return m_pContents->SetColumns((LPSPropTagArray) & Columns, 0) == S_OK;
}
示例#2
0
BOOL CMapiApi::IterateContents( CMapiContentIter *pIter, LPMAPIFOLDER pFolder, ULONG flags)
{
  // flags can be 0 or MAPI_ASSOCIATED
  // MAPI_ASSOCIATED is usually used for forms and views

  HRESULT    hr;
  LPMAPITABLE  lpTable;
  hr = pFolder->GetContentsTable( flags, &lpTable);
  if (FAILED(hr)) {
    MAPI_TRACE2( "GetContentsTable failed: 0x%lx, %d\n", (long)hr, (int)hr);
    return( FALSE);
  }

  ULONG rowCount;
  hr = lpTable->GetRowCount( 0, &rowCount);
  if (!rowCount) {
    MAPI_TRACE0( "  Empty Table\n");
  }

  hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
  if (FAILED(hr)) {
    lpTable->Release();
    MAPI_TRACE2( "SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr);
    return( FALSE);
  }

  hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
  if (FAILED(hr)) {
    lpTable->Release();
    MAPI_TRACE2( "SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr);
    return( FALSE);
  }

  int      cNumRows = 0;
  LPSRowSet  lpRow;
  BOOL    keepGoing = TRUE;
  BOOL    bResult = TRUE;
  do {
    lpRow = NULL;
    hr = lpTable->QueryRows( 1, 0, &lpRow);
    if(HR_FAILED(hr)) {
      MAPI_TRACE2( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr);
      bResult = FALSE;
      break;
    }

    if(lpRow) {
      cNumRows = lpRow->cRows;
      if (cNumRows) {
        LPENTRYID  lpEID = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
        ULONG    cbEID = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
        ULONG    oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;
        keepGoing = HandleContentsItem( oType, cbEID, lpEID);
        MAPI_TRACE1( "    ObjectType: %ld\n", oType);
      }
      FreeProws( lpRow);
    }

  } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing);

  lpTable->Release();
  return( bResult);
}