Here is the code of one of my applications:
bool setXdata()
{
AcDbDictionary *pNamedobj;
AcDbDictionary *pDict;
AcDbXrecord *pXrec;
AcDbObjectId dictObjId, xrecObjId;
struct resbuf *prbXtn;
acdbHostApplicationServices()->workingDatabase()->getNamedObjectsDictionary(
pNamedobj, AcDb::kForWrite);
// if not exist make new
if (pNamedobj->getAt("CCNC_Brandschutz", (AcDbObject*&) pDict,
AcDb::kForWrite) == Acad::eKeyNotFound)
{
pDict = new AcDbDictionary;
pNamedobj->setAt("CCNC_Brandschutz", pDict, dictObjId);
}
// if no xrecord make new
pNamedobj->close();
if (pDict->getAt("CCNC_Fluchtweg", (AcDbObject*&)pXrec, AcDb::kForWrite) ==
Acad::eKeyNotFound)
{
pXrec = new AcDbXrecord;
pDict->setAt("CCNC_Fluchtweg", pXrec, xrecObjId);
}
pDict->close();
char version[12] = "Version_1.0";
AcDbDatabase *pCurDb = NULL;
AcDbLayerTable *pLayerTable;
AcDbObjectId layId;
pCurDb = acdbHostApplicationServices()->workingDatabase();
pCurDb->getLayerTable(pLayerTable, AcDb::kForRead);
pLayerTable->getAt(dlgFlucht.chrLayer, dlgFlucht.idLayer, false);
pLayerTable->close();
ads_name ename;
acdbGetAdsName(ename, dlgFlucht.idLayer);
prbXtn = acutBuildList( AcDb::kDxfText, version,
AcDb::kDxfInt32, dlgFlucht.fl_color,
AcDb::kDxfHardPointerId, ename,
RTNONE);
if(pXrec->setFromRbChain(*prbXtn) != Acad::eOk)
{
acutPrintf("\nFailed");
}
pXrec->close();
acutRelRb(prbXtn);
return true;
}
here is the read out:
bool getXdata()
{
AcDbDictionary *pNamedDict;
AcDbDictionary *pDict;
AcDbXrecord *pXrec;
AcDbObjectId idLayer;
struct resbuf *prbXtn, *pTemp;
acdbHostApplicationServices()->workingDatabase()->getNamedObjectsDictionary(
pNamedDict, AcDb::kForRead);
if (pNamedDict->getAt("CCNC_Brandschutz", (AcDbObject*&) pDict,
AcDb::kForWrite) == Acad::eKeyNotFound)
{
pNamedDict->close();
return false;
}
pNamedDict->close();
if (pDict->getAt("CCNC_Fluchtweg", (AcDbObject*&)pXrec, AcDb::kForRead) ==
Acad::eKeyNotFound)
{
pDict->close();
return false;
}
pDict->close();
pXrec->rbChain(&prbXtn);
pXrec->close();
pTemp = prbXtn;
pTemp = pTemp->rbnext;
if(pTemp->restype == AcDb::kDxfInt32)
dlgFlucht.fl_color = pTemp->resval.rint;
else
return false;
pTemp = pTemp->rbnext;
ads_name ename;
if(pTemp->restype == AcDb::kDxfHardPointerId)
memcpy(ename, pTemp->resval.rlname, sizeof(ads_name));
else
return false;
AcDbObjectId layId;
acdbGetObjectId(layId, ename);
dlgFlucht.idLayer = layId;
ads_relrb(prbXtn);
return true;
}