Iterating over Dictionary Entries

The iterator class for dictionaries is AcDbDictionaryIterator. The following code excerpt obtains a dictionary (ASDK_DICT) from the named object dictionary. It then uses a dictionary iterator to step through the dictionary entries and print the value of the stored integer. Finally, it deletes the iterator and closes the dictionary.

void
iterateDictionary()
{
    AcDbDictionary *pNamedobj;
    acdbHostApplicationServices()->workingDatabase()
        ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);
    // Get a pointer to the ASDK_DICT dictionary.
    //
    AcDbDictionary *pDict;
    pNamedobj->getAt("ASDK_DICT", (AcDbObject*&)pDict,
        AcDb::kForRead);
    pNamedobj->close();
    // Get an iterator for the ASDK_DICT dictionary.
    //
    AcDbDictionaryIterator* pDictIter = pDict->newIterator();
    AsdkMyClass *pMyCl;
    Adesk::Int16 val;
    for (; !pDictIter->done(); pDictIter->next()) {
        // Get the current record, open it for read, and
        // print its data.
        //
        pDictIter->getObject((AcDbObject*&)pMyCl,
            AcDb::kForRead);
        pMyCl->getData(val);
        pMyCl->close();
        acutPrintf("\nintval is:  %d", val);
    }
    delete pDictIter;
    pDict->close();
}