在DLL中反序列化类的问题 [英] Problem deserializing class in DLL

查看:112
本文介绍了在DLL中反序列化类的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在使用相同程序的更加开发的VS2015版本反序列化使用VS2010 C ++程序创建的文件时遇到问题。



有些类已被移入DLL中,我已适当地更改了DECLARE_SERIAL和IMPLEMENT_SERIAL宏。几乎所有旧文件都加载完美,反序列化移入DLL的类没有问题。



程序结构本质上是这样的,每个类都将反序列化传递给它的基础class:



DLL包含:



Hi all,

I have a problem deserializing a file created with a VS2010 C++ program using a more-developed VS2015 version of the same program.

Some of the classes have been moved into DLLs, and I have changed the DECLARE_SERIAL and IMPLEMENT_SERIAL macros appropriately. Almost all old files load perfectly, deserializing classes moved into the DLL without issue.

The program structure is in essence this, with each class passing the deserialization up to its base class:

DLL contains:

CBaseDLL : public CObject {...};

CDerivedDLL1 : public CBaseDLL {...};

CDerivedDLL2 : public CDerivedDLL1 {...};





EXE包含:





EXE contains:

CDerivedExe1 : public CBaseDLL 
{
    ....;
    CDerivedDLL2 *m_d2;

    void Serialize(CArchive &ar) {
        CBaseDLL::Serialize(ar);
        ar >> ....;
        ar >> m_d2;
    }
}

CDerivedExe2 : public CDerivedExe1
{
    ....;

    void Serialize(CArchive &ar) {
        CDerivedExe1::Serialize(ar);
        ar >> ....;
    }
}

CDocExe::Serialize()
{
	for (int i=0; i<3; ++i)
	{
		CDerivedExe2 *de2;
		ar >> de2;
	}
}





奇怪的是文件中有三个CDerivedExe对象。第一个正确加载。第二个失败。



我尝试过:



我已经直接进入MFC加载代码,问题出在CArchive :: ReadClass()(arcobj.cpp的第493行),其中m_pLoadArray返回它尝试加载的类是CDerivedDLL2而不是CDerivedExe2。我假设在某个地方,反序列化对于它是在查找DLL类还是在EXE类中感到困惑,但我不明白它为什么会工作一次然后失败。



感激不尽的任何建议!



The odd thing is that there are three CDerivedExe objects in the file. The first one loads correctly. The second one fails.

What I have tried:

I have stepped right into the MFC loading code and the problem is in CArchive::ReadClass() (line 493 of arcobj.cpp), where m_pLoadArray returns that the class it is trying to load is of type CDerivedDLL2 instead of CDerivedExe2. I am assuming that somewhere the deserialization is getting confused about whether it's looking up a DLL class or an EXE class, but I can't see why it is working once and then failing.

Any suggestions gratefully received!

推荐答案

你必须覆盖>>运营商解决此问题。如果踩着调试器进入>>操作员你应该看到它。



恕我直言:从dll覆盖类不是一个好主意或明确的设计。
You must override the >> operator to fix this issue. If stepping with the debugger into the >> operator you should see it.

IMHO: it isnt a good idea or clear design to overwrite classes from a dll.


一个古老的补丁不是将类移动到DLL后,允许正确构建CArchive反序列化代码中的类映射。现在全部工作。
An ancient patch wasn't allowing the Class map in the CArchive deserialization code to be built up correctly once the classes were moved to the DLL. All working now.


这篇关于在DLL中反序列化类的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆