p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Ivor Horton's Beginning Visual C++ 2005 (http://p2p.wrox.com/book-ivor-hortons-beginning-visual-c-2005-249/)
-   -   Ch 18 - Deserialisation problem using dll classes (http://p2p.wrox.com/book-ivor-hortons-beginning-visual-c-2005/54169-ch-18-deserialisation-problem-using-dll-classes.html)

Dan6 February 16th, 2007 12:47 PM

Ch 18 - Deserialisation problem using dll classes
 
I was just wondering if anyone else has come across the same deserialisation problem I've found when using the element classes in the dll file. Sketcher seems to work fine with the dll file and will correctly serialise a document. However, when it comes to reading a file back into the program, it claims "Unexpected file format" and looking at the debug trace it's not able to load the appropriate class. It throws "CArchive exception: badClass".

Looking at the list of loaded modules shows that the dll file is amongst them and the program has no problem drawing any of these elements, or serialising them, so I can't understand why it can't seem to find the class.

Looking around on the net I came across this on the Microsoft website, which is exactly the problem I'm having:

http://support.microsoft.com/kb/322621

However, this article was last reviewed in 2005 when it applied to Visual Studio.NET 2002. So the fix for this bug, which was included in service pack 1 for that version, should surely be included in my standard version of Visual Studio 2005 shouldn't it? I've installed SP1 for my version of the program so it should be as up to date as it can be. But the problem still remains.

Has anyone else using Visual Studio 2005 had this problem?


Dan6 February 20th, 2007 01:05 PM

I seem to have found the source of my own problem. Thought I'd post it on here in case anyone else gets frustrated by the same thing.

The problem was that I was using different character sets for the dll project and the Sketcher project. The character set option seems to have a powerful effect on what the linker links to in the project. Looking at the bottom of the 'stdafx.h' file shows that when _UNICODE is defined, the linker links to a different control set. I don't know whether a control set is a different set of MFC or not, but it does seem to change the appearance of the Sketcher program quite substantially. It makes it look much more like XP.

Anyway, the moral of the story is to make sure that in the project properties boxes for both the dll and the program the same character set is selected, whether this is multi-byte or unicode. Just make sure you use the same one for both - that's where I fell down.

I hope this helps someone.

Dan



All times are GMT -4. The time now is 07:02 AM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.