-
May 13th, 2009, 04:02 PM
#1
CArchive issue?
I'm getting an exception thrown for CArchive. This is code that worked in a VS6 (COM) DLL that is being updated to VS8 (VS.NET 2005) and an MFC DLL (removed COM).
Relevant Code:
Code:
CString strName = _T("");
CSequence* pSequence = NULL;
CFile file;
CFileException fe;
CString msg;
// open file
if (!file.Open(strFilePath, CFile::modeRead | CFile::shareDenyWrite, &fe))
{
// Error handling - no file open issues
}
CArchive ar(&file, CArchive::load);
ar >> pSequence; // **EXCEPTION
ar.Close();
file.Close();
Exception happens at the ar >> pSequence line.
For the CSequence class, the constructor with CArchive is a Serialize.
Code:
virtual void Serialize(CArchive& ar);
When it reads the files (created a long time ago, but still working on the older system), it throws an exception:
<filename> contained an unexpected objet.
Any ideas? Thoughts?
Is CArchive compatible with older version of CArchive? I'm guessing that's how those files were created in the first place.
-
May 13th, 2009, 05:44 PM
#2
Re: CArchive issue?
Originally Posted by KingTermite
Is CArchive compatible with older version of CArchive? I'm guessing that's how those files were created in the first place.
I'm not sure if it's compatible or not. Make sure that you have added any new fields to the 2008 program. If it is going to work, it must be an exact match of the old code. Even then it's doubtful that it will work.
If it is mission critical that you convert the old data files to the new format, consider writing out the old files (using a modified version of the VC6 program) to another format like xml. Then add some temp code to the new VC8 project that takes the xml, creates mfc objects that you can serialize into the new format.
Last edited by Arjay; May 13th, 2009 at 05:48 PM.
-
May 14th, 2009, 05:57 AM
#3
Re: CArchive issue?
You should also check your CSequence class to be sure none of the serialized members has changed in size.
For instance, in VS6, a CTime object when serialized used 4 bytes, but under VS2005, a CTime object is 12 bytes. That change sure could mess things up.
Good luck.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
May 14th, 2009, 06:36 AM
#4
Re: CArchive issue?
I don't use CArchive ... but this looks suspect to me:
Code:
CSequence* pSequence = NULL;
ar >> pSequence;
Did you just archive a memory location ? Or a CSequence object ?
-
May 14th, 2009, 02:20 PM
#5
Re: CArchive issue?
Originally Posted by Philip Nicoletti
I don't use CArchive ... but this looks suspect to me:
Code:
CSequence* pSequence = NULL;
ar >> pSequence;
Did you just archive a memory location ? Or a CSequence object ?
It appears to be creating the archive from the file, then writing it out as a CSequence to that pSequence pointer. I looked in the old on (through debugger) and the >> operator appears to allocate the memory. I'm guessing the NULL pointer was what made you suspicious.
-
May 14th, 2009, 02:21 PM
#6
Re: CArchive issue?
Originally Posted by krmed
You should also check your CSequence class to be sure none of the serialized members has changed in size.
For instance, in VS6, a CTime object when serialized used 4 bytes, but under VS2005, a CTime object is 12 bytes. That change sure could mess things up.
Good luck.
This to me seems the most likely. I've looked at where its serializing out and it appears to only be CStrings and some normal data types (longs, ints, doubles, etc...).
-
May 14th, 2009, 03:43 PM
#7
Re: CArchive issue?
One other thing to think about - did you migrate the project (through Visual Studio) or did you re-create it?
In either case, check to make sure you're using the same character set - VS6 used MBCS by default whereas VS2005 uses Unicode. This would cause your CStrings to be changed. (requiring almost double the space).
Good luck.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|