Problems when re-compiling a VC 6 Project with VC 2012
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Problems when re-compiling a VC 6 Project with VC 2012

  1. #1
    Join Date
    Nov 2017
    Posts
    1

    Question Problems when re-compiling a VC 6 Project with VC 2012

    Hi, Friends

    when re-compiling an old VC 6 project with VC 2012, i encouterring this errors:

    the code:

    CRorEditView::CRorEditView()
    {
    AFX_ZERO_INIT_OBJECT(CRorTextView);
    }

    RorTextView::CRorTextView()
    {
    AFX_ZERO_INIT_OBJECT(CScrollView);
    ResetView();
    }

    the errors:

    1> CRorEditView.cpp
    1>c:\exetoc\exe2c_gui\croreditview.cpp(34): error C2275: 'CRorTextView' : illegal use of this type as an expression
    1>c:\exetoc\exe2c_gui\croreditview.cpp(34): error C3861: 'AFX_ZERO_INIT_OBJECT': identifier not found
    1> CRorTextView.cpp
    1>c:\exetoc\exe2c_gui\crortextview.cpp(116): error C2275: 'CScrollView' : illegal use of this type as an expression
    1>c:\exetoc\exe2c_gui\crortextview.cpp(116): error C3861: 'AFX_ZERO_INIT_OBJECT': identifier not found
    1> Generating Code...

    as i dont have a good experience with MFC, i dont know the problem exactly, I searched in net, i find mybe microsoft have changed this class, but there no information about this change, and which class
    has replaced.

    Any information is appreciated.

    Thanks.
    Best regard.
    DJYA.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,998

    Re: Problems when re-compiling a VC 6 Project with VC 2012

    Well, begin with this thread...
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,187

    Re: Problems when re-compiling a VC 6 Project with VC 2012

    Completing what Victor already pointed

    AFX_ZERO_INIT_OBJECT is a undocumented macro which has been removed in newer MFC versions. Having a look at MFC Macros and Globals in VC6.0 documentation, can notice that it was indeed undocumented. A rule of thumb is "avoid as much as possible using the undocumented stuff in your code". In a further implementation that stuff can be changed or simply disappear. Sh*t happens.

    Let's have a look in this article: https://weseetips.wordpress.com/tag/...o_init_object/
    Code:
    // zero fill everything after the vtbl pointer
    #define AFX_ZERO_INIT_OBJECT(base_class) \
    memset(((base_class*)this)+1, 0, sizeof(*this) - sizeof(class base_class));
    // Spooky!
    No wonder why AFX_ZERO_INIT_OBJECT was erased from MFC framework and now CDialog's constructor looks like this:
    Code:
    CDialog::CDialog()
    {
        // ...
        Initialize();
    }
    void CDialog::Initialize()
    {
        m_nIDHelp = 0;
        m_lpszTemplateName = NULL;
        // ...
    }
    Do the same: GET RID OF AFX_ZERO_INIT_OBJECT and initialize yourself the member variables. A little bit better is in the constructor's members initializer list, like for example:
    Code:
    CYourClass::CYourClass()
        : m_pSomeMember(NULL), m_pSomeOtherMember(NULL) // ...
    {
    
    }
    Last edited by ovidiucucu; November 15th, 2017 at 03:01 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #4
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,187

    Re: Problems when re-compiling a VC 6 Project with VC 2012

    A little bit beyond the topic...

    If your C++ compiler supports last C++ standards (C++11 and newer) features, you can write, for example, something like this:
    Code:
    class CFooWnd : public CWnd
    {
    public:
        CFooWnd() = default;
        virtual ~CFooWnd() = default;
        // ...
    private:
        CWnd* m_pWndParent = NULL;
        CString m_strCaption = _T("Unknown");
        // ...
    };
    That simplified the code because neither a Initialize method, nor a constructor's members initializer list is necessary. It works in Visual Studio 2013 and newer, but not in Visual Studio 2012.
    See Non-static data member initializers here: https://msdn.microsoft.com/en-us/lib...v=vs.140).aspx.

    // It's time to migrate to a newer Visual Studio version... I truly recommend 2017.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)