VC7: BUG in IMPLEMENT_SERIAL (MFC) 
Author Message
 VC7: BUG in IMPLEMENT_SERIAL (MFC)

The new version of IMPLEMENT_SERIAL sometimes emits false code, that causes
in a corrupt serialisation because objects not found.

The following fixes the problem:
#undef IMPLEMENT_SERIAL
#define IMPLEMENT_SERIAL(class_name, base_class_name, wSchema) \
      CObject* Pascal class_name::CreateObject() \
            { return new class_name; } \
      _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, \
            class_name::CreateObject, NULL) \
      AFX_COMDAT AFX_CLASSINIT
_init_##class_name(RUNTIME_CLASS(class_name)); \
      CArchive& AFXAPI operator>>(CArchive& ar, class_name* &pOb) \
            { pOb = (class_name*) ar.ReadObject(RUNTIME_CLASS(class_name));
\
                  return ar; } \

Background:
In the original implementation of VC7 (afx.h) the lines
_IMPLEMENT_RUNTIMECLASS and AFX_COMDAT AFX_CLASSINIT are exchanged, this
caused to wrong runtime initialization if the compiler emits a
initialisation function for constructing CRuntimeClass in
(_IMPLEMENT_RUNTIMECLASS).
AfxClassInit is called in the constructor from AXF_CLASSINIT before the
runtime-class is initialized. This results in setting
CRuntimeClass::m_pNextClass to zero, which destroys the linked list in
AFX_MODULE_STATE::m_classlist (All before inserted objects are lost)
The order of these two calls is occasionally changed in cause of the the
Member m_pClassInit of CRuntimeClass. But I mentioned no usage so that I set
this one to NULL.

Regards Bernd

Bernd Oerding; Leiter Programmentwicklung CAD/GIS
HHK Datentechnik GmbH; Richard-Wagner-Stra?e 1-2; 38106 Braunschweig
CAD/GIS fr Vermesser, Kommunen und Versorger http://www.*-*-*.com/



Fri, 24 Dec 2004 15:36:55 GMT  
 VC7: BUG in IMPLEMENT_SERIAL (MFC)
We have had exactly the same problem. Thank you for the
solution. BUT BUT has anyone at Microsoft seen this and
reported it to the dev team??? It seems to be time for a
SP!

Quote:
>-----Original Message-----
>The new version of IMPLEMENT_SERIAL sometimes emits false
code, that causes
>in a corrupt serialisation because objects not found.

>The following fixes the problem:
>#undef IMPLEMENT_SERIAL
>#define IMPLEMENT_SERIAL(class_name, base_class_name,
wSchema) \
>      CObject* PASCAL class_name::CreateObject() \
>            { return new class_name; } \
>      _IMPLEMENT_RUNTIMECLASS(class_name,

base_class_name, wSchema, \
Quote:
>            class_name::CreateObject, NULL) \
>      AFX_COMDAT AFX_CLASSINIT
>_init_##class_name(RUNTIME_CLASS(class_name)); \
>      CArchive& AFXAPI operator>>(CArchive& ar,
class_name* &pOb) \
>            { pOb = (class_name*) ar.ReadObject

(RUNTIME_CLASS(class_name));
Quote:
>\
>                  return ar; } \

>Background:
>In the original implementation of VC7 (afx.h) the lines
>_IMPLEMENT_RUNTIMECLASS and AFX_COMDAT AFX_CLASSINIT are
exchanged, this
>caused to wrong runtime initialization if the compiler
emits a
>initialisation function for constructing CRuntimeClass in
>(_IMPLEMENT_RUNTIMECLASS).
>AfxClassInit is called in the constructor from

AXF_CLASSINIT before the
Quote:
>runtime-class is initialized. This results in setting
>CRuntimeClass::m_pNextClass to zero, which destroys the
linked list in
>AFX_MODULE_STATE::m_classlist (All before inserted
objects are lost)
>The order of these two calls is occasionally changed in
cause of the the
>Member m_pClassInit of CRuntimeClass. But I mentioned no
usage so that I set
>this one to NULL.

>Regards Bernd

>Bernd Oerding; Leiter Programmentwicklung CAD/GIS
>HHK Datentechnik GmbH; Richard-Wagner-Stra?e 1-2; 38106
Braunschweig
>CAD/GIS fr Vermesser, Kommunen und Versorger

http://www.geografis.de

- Show quoted text -

Quote:

>.



Tue, 22 Mar 2005 13:02:29 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Found bug in vc7 mfc code...

2. BUG with VC7 RC1 with an MFC AppWizard generated CEditView project

3. possible bug in VC6, VC7, VC7.1

4. Possible bug in vc7.0 (and vc7.1)

5. Bug: VC7 MFC CByteArray::Serialize

6. IMPLEMENT_SERIAL bug

7. my bug or VC7 bug ?

8. VC7.1 covariant return bug?

9. VC7.1 C++ bug: incorrect definition of the constructor of a template accepted

10. VC7 IDE bug?

11. VC7 adds a new twist to an old C++ compiler bug

12. VC6/VC7 bug with ?: operator and throw expressions.

 

 
Powered by phpBB® Forum Software