Deserialization stops working if I load MFC DLL from regular DLL

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small Deserialization stops working if I load MFC DLL from regular DLL
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small I have been asking this question before, but at that time I think it was to complex so I did not get any answer solving the problem for me.
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small See
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/451add54-2813-4626-aa28-a7753605f69a <span style="font-family:Calibri; font-size:small http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/451add54-2813-4626-aa28-a7753605f69a
<span style="font-family:Calibri; font-size:small
Now I have made a test application showing the same problem. <br/>
You can find the zipped code files at https://skydrive.live.com/?#cid=0977B1167FE01BB3&id=977B1167FE01BB3%21105&sc=documents
https://skydrive.live.com/?#cid=0977B1167FE01BB3&id=977B1167FE01BB3%21105&sc=documents .

If I load a MFC extension DLL from a regular DLL then deserialization stop working if I call the MFC Extension DLL directly from the application.
<img src="http://social.microsoft.com/Forums/getfile/58132/" alt="
When I try to deserialize I get the following CArchiveException "an unnamed file contained an unexpected object."
In addition the output in Visual Studio 2008 gives the following information when I run the debug version of SerializeTest:
âWarning: Cannot load CSerializableClass from archive. Class not defined. CArchive exception: badClass. First-chance exception at 0x7c812afb in SerializeTestD.exe: Microsoft C++ exception: CArchiveException at memory location 0x0012edf8.â
The following test code is run in CMFCDLL::DoIt
<span style="font-family:Calibri; font-size:small
<div style="background-color:white; color:black
<pre><span style="color:blue void CMFCDLL::DoIt(<span style="color:blue void)
{

BYTE * pBuf = (BYTE *)<span style="color:blue new <span style="color:blue char [1024];
{
CSerializableClass *pSerializableClass = <span style="color:blue new CSerializableClass;

CMemFile mf;
mf.Attach(pBuf, 1024);

CArchive ar(&mf, CArchive::store);
ar << pSerializableClass;
ar.Close();
mf.Detach();

<span style="color:blue delete pSerializableClass;
}
{
CSerializableClass *pSerializableClass = NULL;

CMemFile mf;
mf.Attach(pBuf, 1024);
CArchive ar(&mf, CArchive::load);
<span style="color:blue try
{
ar >> pSerializableClass;
ar.Close();
mf.Detach();

ASSERT(pSerializableClass && pSerializableClass->GetText() == _T(<span style="color:#a31515 "This is a serialize test"));

<span style="color:blue delete pSerializableClass;
}
<span style="color:blue catch(CArchiveException *p)
{
<span style="color:blue char str[500];
p->GetErrorMessage(str,500);
AfxMessageBox(str);
p->Delete();

ar.Abort();
mf.Detach();
}
}
<span style="color:blue delete pBuf;
}

[/code]

The code that fails is "ar >> pSerializableClass". Any ideas why I get this problem?
Why do I have to use a regular DLL?<br/>
I am writing a .NET wrapper and the mixed mode DLL is a regular DLL accessing serialization in a MFC Extension DLL.

<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<p style="margin:0cm 0cm 0pt <span style="font-family:Calibri; font-size:small
<
Senior Software Engineer R&D<br/>

View the full article
 
Back
Top