~~~~~~~~~~~~~~~~!!!!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    你看看源代码就知道了。void CArchive::WriteObject(const CObject* pOb)
    {
    // object can be NULL ASSERT(IsStoring());    // proper direction if (!IsStoring()) 
    {
    AfxThrowArchiveException(CArchiveException::readOnly, m_strFileName);
    } DWORD nObIndex;
    ASSERT(sizeof(nObIndex) == 4);
    ASSERT(sizeof(wNullTag) == 2);
    ASSERT(sizeof(wBigObjectTag) == 2);
    ASSERT(sizeof(wNewClassTag) == 2); // make sure m_pStoreMap is initialized
    MapObject(NULL); if (pOb == NULL)
    {
    // save out null tag to represent NULL pointer
    *this << wNullTag;
    }
    else if ((nObIndex = (DWORD)(DWORD_PTR)(*m_pStoreMap)[(void*)pOb]) != 0)
    // assumes initialized to 0 map
    {
    // save out index of already stored object
    if (nObIndex < wBigObjectTag)
    *this << (WORD)nObIndex;
    else
    {
    *this << wBigObjectTag;
    *this << nObIndex;
    }
    }
    else
    {
    // write class of object first
    CRuntimeClass* pClassRef = pOb->GetRuntimeClass();
    WriteClass(pClassRef); // enter in stored object table, checking for overflow
    CheckCount();
    (*m_pStoreMap)[(void*)pOb] = (void*)(DWORD_PTR)m_nMapCount++; // cause the object to serialize itself
    ((CObject*)pOb)->Serialize(*this);
    }
    }CObject* CArchive::ReadObject(const CRuntimeClass* pClassRefRequested)
    {
    ASSERT(pClassRefRequested == NULL ||
    AfxIsValidAddress(pClassRefRequested, sizeof(CRuntimeClass), FALSE));
    ASSERT(IsLoading());    // proper direction
    ASSERT(wNullTag == 0);
    ASSERT((wClassTag << 16) == dwBigClassTag);
    ASSERT((wNewClassTag & wClassTag) == wClassTag); if (!IsLoading()) 
    {
    AfxThrowArchiveException(CArchiveException::writeOnly, m_strFileName);
    } // attempt to load next stream as CRuntimeClass
    UINT nSchema;
    DWORD obTag;
    CRuntimeClass* pClassRef = ReadClass(pClassRefRequested, &nSchema, &obTag); // check to see if tag to already loaded object
    CObject* pOb;
    if (pClassRef == NULL)
    {
    if (obTag > (DWORD)m_pLoadArray->GetUpperBound())
    {
    // tag is too large for the number of objects read so far
    AfxThrowArchiveException(CArchiveException::badIndex,
    m_strFileName);
    } pOb = (CObject*)m_pLoadArray->GetAt(obTag);
    if (pOb != NULL && pClassRefRequested != NULL &&
     !pOb->IsKindOf(pClassRefRequested))
    {
    // loaded an object but of the wrong class
    AfxThrowArchiveException(CArchiveException::badClass,
    m_strFileName);
    }
    }
    else
    {
    // allocate a new object based on the class just acquired
    pOb = pClassRef->CreateObject();
    if (pOb == NULL)
    AfxThrowMemoryException(); // Add to mapping array BEFORE de-serializing
    CheckCount();
    m_pLoadArray->InsertAt(m_nMapCount++, pOb); // Serialize the object with the schema number set in the archive
    UINT nSchemaSave = m_nObjectSchema;
    m_nObjectSchema = nSchema;
    pOb->Serialize(*this);
    m_nObjectSchema = nSchemaSave;
    ASSERT_VALID(pOb);
    } return pOb;
    }
      

  2.   

    寒 ~~~!!! 程序里面是知道 但是我怎么知道啊  用iskindof 判断 一个一个的?~~~
      

  3.   

    如果你是程序里面要自己判断,当然只能一个一个来做了。除非你序列化读入后已经创建了对象,那么用CObject::GetRuntimeClass()->m_lpszClassName就可以得到类名。