反序列化停止使用运行时库设置作为发布版本的多线程DLL(/ MD) [英] Deserialization stops working with Runtime Library setting as Multi-threaded DLL (/MD) for Release build

查看:52
本文介绍了反序列化停止使用运行时库设置作为发布版本的多线程DLL(/ MD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用COblist序列化来存储和从文件加载嵌套列表数据。但是,当尝试反序列化/读取存档文件以检索数据时会出现异常。请注意,主应用程序读取文件并创建CArchive对象为Load,
存储该文件,此存档将传递给CObList序列化。

Using COblist serialize to store and load nested list data to/from file. However gets an exception when try to deserialize/read the archived file back to retrieve the data. Note that main application reads the file and creates CArchive object to Load and Store the file, and this archive is passed to CObList serialize.

//

CFile f ;

CFile f;

f.Open( data.dat, CFile :: modeRead

f.Open(data.dat, CFile::modeRead) ; 

CArchive ar(& f,
< span style ="color:#2b91af; font-size:small"> CArchive :: load
;

CArchivear(&f, CArchive::load) ;

m_LimitTestScenarios.Seri alize(ar); //请参阅下面的CLimitTestScenarios :: Serialize在单独的DLL中实现 

m_LimitTestScenarios.Serialize(ar) ; // See CLimitTestScenarios::Serialize below implemented in separate DLL 

ar.Close();

ar.Close() ;

///

///写入/序列化代码...但工作正常

///Write/Serialize code ... works fine though

f.Open(data.dat, CFile :: modeWrite |
CFile :: modeCreate
;  

f.Open(data.dat, CFile::modeWrite| CFile::modeCreate) ; 

CArchive ar(& f,
CArchive :: store
;

CArchivear(&f, CArchive::store) ;

m_LimitsTestScenarios.Serialize(ar); //< -Calls相同的DLL
CLimitsTestScenarios
:: Serialize in Read /加载

m_LimitsTestScenarios.Serialize(ar) ; //<-Calls same DLL CLimitsTestScenarios::Serialize as in Read/Load

ar.Close();

ar.Close() ;

///

///

// CLimitsTestScenarios
在单独的DLL中实现。

// CLimitsTestScenarios implemented in separate DLL.

// DLL类.... h

// DLL Class....h

class VISIBILITY CLimitsTestScenarios
public _ CTypedPtrList < CObList
CLimitsStandGroup *>

class VISIBILITYCLimitsTestScenarios: public_CTypedPtrList<CObList, CLimitsStandGroup*>

{

DECLARE_SERIAL CLimitsTestScenarios

DECLARE_SERIAL (CLimitsTestScenarios)

public CLimitsTestScenarios();

public:CLimitsTestScenarios() ;

虚拟 ~CLimitsTestScenarios();

virtual~CLimitsTestScenarios() ;

virtual void 序列化( CArchive & ar)
;

virtual voidSerialize(CArchive&ar) ;

};

// DLL类.cpp

// DLL Class .cpp

IMPLEMENT_SERIAL CLimitsTestScenarios
< span style ="color:#2b91af; font-size:small"> CObList ,0)

IMPLEMENT_SERIAL(CLimitsTestScenarios, CObList, 0)

CLimitsTestScenarios :: CLimitsTestScenarios():
_ CTypedPtrList < CObList
CLimitsStandGroup *>()

CLimitsTestScenarios::CLimitsTestScenarios() : _CTypedPtrList<CObList, CLimitsStandGroup*>()

{

}

//此序列化函数DLL

// Serialize function in this DLL

void CLimitsTestScenarios :: Serialize( CArchive & ar

void CLimitsTestScenarios::Serialize(CArchive&ar)

{

CObList :: Serialize( ar
;
//< - 抛出异常'Data.dat包含一个意外的对象

CObList::Serialize(ar) ; // <- throws exception 'Data.dat contained an unexpected object

}

////

但是上面的代码工作正常,反序列化并在调试模式下正确地检索数据,或者我只是通过一次设置更改来编译DLL,即配置属性 - > C / C ++ - >代码生成 - >运行时库为'多线程
调试DLL(/ MDd)。

However above code works fine, deserialize and retrives the data properly in Debug mode or I just compile the DLL with one setting change, that is Configuration Properties->C/C++ -> Code Generation -> Runtime Library as 'Multi-threaded Debug DLL (/MDd).

我想上面的运行时库设置(在调试版本和版本构建中我是改进的)是使用调试运行时图书馆要使它在发布模式下工作,发布模式默认设置为'多线程DLL(/ MD)???

I guess the above runtime library setting (which is defult in debug build and in Release build I changed)is using debug runtime libraries. How to make it work in Release mode with Release mode default setting 'Multi-threaded DLL (/MD)???

此外,如果我只想提出一个解决方法(不是一个好主意)虽然),通过使用运行时库构建此DLL作为'多线程调试DLL(/ MDd),应用程序将不会启动并给出错误C000000B7。

Also if I just want to put a workaround (not a good idea though), by having build this DLL with Runtime Library as 'Multi-threaded Debug DLL (/MDd), the application won't launch and gives error C000000B7.

我想构建并使其在Release模式下工作,运行时库设置为'多线程DLL(/ MD)。感谢任何输入。

I would like to build and make it work in Release mode with Runtime Library setting as 'Multi-threaded DLL (/MD). Appreciate any inputs.

-PB

推荐答案

我为没有研究你的代码而道歉,但我怀疑有两个不同的问题。我不确定我理解你在说什么,但你可能会说该程序对于调试和发布版本的工作方式不同。我不认为问题
是由应用程序链接的方式引起的;它更可能是由你在代码中忽略的事情引起的。调试构建执行诸如初始化源代码不执行的变量以及发布构建不执行初始化之类的操作。所以
换句话说可能有一些你没有初始化的东西,调试版本没有问题但发布版本会有问题。
I apologize for not studying your code but I suspect that there are two separate problems. I am not sure I understand what you are saying but you are probably saying that the program works differently for debug and release builds. I don't think that problem is caused by the way the application is linked; it is more likely to be caused by something you overlook doing in the code. Debug builds do things like initialize variables that the source code does not do and release builds do not do the initialization. So in other words there might be something you are not initializing and the debug build does not have a problem but the release build would have the problem.


这篇关于反序列化停止使用运行时库设置作为发布版本的多线程DLL(/ MD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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