locked
After converting from VS 2008 to 2010: C2504: 'CDialog': base class undefined

    Question

  • Hi,

    I want to convert my projects from VS 2008 to VS 2010. I can compile the project in VS 2008 without an error, but in VS 2010 I got a lot of them. The first is:
    error C2504: 'CDialog': base class undefined  (or in german: error C2504: 'CDialog': Basisklasse undefiniert)

    #if !defined(AFX_FILTER_H__799593D3_2E44_11D5_B312_00B0D08AC686__INCLUDED_)
    #define AFX_FILTER_H__799593D3_2E44_11D5_B312_00B0D08AC686__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // Filter.h : Header-Datei
    //
    
    /////////////////////////////////////////////////////////////////////////////
    // Dialogfeld CFilter 
    
    class CFilter : public CDialog
    {  // <-- HERE COMES THE ERROR
    

    What can I do? (I'm not very familiar with the MFC. The projects are old and "designed" from other developers. :( )

     

    Thanks,


    Mike

    Thursday, July 22, 2010 9:40 AM

Answers

  • At the end, I removed my CFilter class and the filter.cpp and filter.h from the project. After that, I added a new MFC - class with a different name: CFilterDialog and "restore" the code from the old files. And ...

    ... that works. I can compile the complete solution, without any warnings!

     

    But:

    I closed Visual Studio, delete the folder with the project and got the latest version from the Repository. If I look than into the "Externe Abhängigkeiten" (?external depencencies), there is still an entry for a file named filter.h, but this points now to c:\program files\microsoft sdks\windows\v7.0a\include\filter.h ... (and not to "my" file). Maybe there is a problem with the new MSBuild in VS 2010?

    Ciao,

    Mike

    • Marked as answer by mike969 Monday, July 26, 2010 9:54 AM
    Monday, July 26, 2010 9:54 AM

All replies

  • Hi,
     
    I want to convert my projects from VS 2008 to VS 2010. I can compile the project in VS 2008 without an error, but in VS 2010 I got a lot of them. The first is:
    error C2504: 'CDialog': base class undefined (or in german: error C2504: 'CDialog': Basisklasse undefiniert)
    It seems that you might be missing the MFC headers. Does the .cpp file for this class (and any other .cpp file that #include's its header) have
     
    #include "stdafx.h"
     
    as the first line? If so, what is in stdafx.h?
     

    David Wilkinson | Visual C++ MVP
    Thursday, July 22, 2010 9:49 AM
  • Hi Dave,

    thanks for your fast reply!

    Filter.cpp starts with:

    // Filter.cpp: Implementierungsdatei
    //
    #define WINVER 0x0501
    
    #include "stdafx.h"
    

    And the StdAfx.h starts with:

    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    //   are changed infrequently
    //
    #define WINVER 0x0501
    #define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
    #pragma warning(disable : 4996)
    
    
        
    
    #include <afxwin.h>     // MFC core and standard components
    #include <afxext.h>     // MFC extensions
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>			// MFC support for Windows 95 Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    
    
    

     

    And if some headers are really missing, why after the conversion and not within VS 2008? Could it be a problem of the project settings?

     

    Ciao,

    Mike

    Thursday, July 22, 2010 11:24 AM
  • Hi Dave,
     
    thanks for your fast reply!
     
    Filter.cpp starts with:
     
    // Filter.cpp: Implementierungsdatei
    //
    #define WINVER 0x0501
     
    #include "stdafx.h"
    This may not be the problem, but
     
    #include "stdafx.h"
     
    should always be the first non-commented line in the file. You certainly do not need this #define, because you have it in stdafx.h.
     
    Is this filter.cpp the only file that does not compile? What happens if you open another .cpp file and try to compile it bt itself?
     

    David Wilkinson | Visual C++ MVP
    Thursday, July 22, 2010 12:11 PM
  • #include "stdafx.h"
    should always be the first non-commented line in the file.
    No changes, the same errors.
    Is this filter.cpp the only file that does not compile? What happens if you open another .cpp file and try to compile it bt itself?

    I take a small class, with only two includes in the .cpp and none in the .h:


    // AbsPro.h - Absaug-Profil
    
    
    #define WINVER 0x0501
    #pragma warning(disable : 4996)
    
    #include <afxwin.h>
    #include <abspro.h>
    
    // Konstruktor
    
    
    CAbsaugProfil::CAbsaugProfil()
    {
    

     

    Take a look at the output:

    1>------ Erstellen gestartet: Projekt: xyz, Konfiguration: Debug Win32 ------
    1> AbsPro.cpp
    1>d:\xyz\filter.h(14): error C2504: 'CDialog': Basisklasse undefiniert
    1>d:\xyz\filter.h(32): error C2065: 'IDD_FILTER': nichtdeklarierter Bezeichner
    ...

    If I'm right, only this one file should be compiled, but not the filter.h?

    UPDATE: If I try to compile a .cpp which does not use #include <afxwin.h> it works. I can compile it, without any errors.

    Ciao,

    Mike

    Thursday, July 22, 2010 12:34 PM
  • Build a new default MFC proect (File, New, Project, MFC, Application) to see if your Visual Studio installation is complete (or not).
    Thursday, July 22, 2010 1:28 PM
  • I have to convert about 20 projects. 11 of them are still running under VS 2010 ...

    But nevertheless: A new default MFC profect could be build and run without any errors or warnings.

     

    Thursday, July 22, 2010 1:44 PM
  • Maybe a problem with the C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\filter.h ???
    Thursday, July 22, 2010 2:27 PM
  •  "mike969" wrote in message news:43e2ab77-cbfc-4dbe-bf20-420315745718@communitybridge.codeplex.com...

    Filter.cpp starts with:


    // Filter.cpp: Implementierungsdatei // #define WINVER 0x0501 #include "stdafx.h"

    And the StdAfx.h starts with:

    [code]

    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    //   are changed infrequently
    //
    #define WINVER 0x0501
    #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
    #pragma warning(disable : 4996)

    If WINVER is defined in stdafx.h, you don't actually need it in the cpp file.

    But the value 0x0501 has been causing me some trouble with VS2010 - as yet not completely resolved.   Just as an experiment, try removing the definition from the file AND from stdafx.h and see if it fixes the problem. (By default VS2010 will use the latest value of WINVER which it knows about.)     If it works, and you're using Vista or Win7, then do test your program on an XP machine.

    Dave


    David Webber
    Mozart Music Software
    http://www.mozart.co.uk
    For discussion and support see
    http://www.mozart.co.uk/mozartists/mailinglist.htm


    David Webber Author of Mozart music notation software http://www.mozart.co.uk
    Thursday, July 22, 2010 5:50 PM
  • I remove the definition of WINVER from the .cpp and StdAfx.h, but without success. The number of errors seems to increase. (And we use only Win XP here.)
    Friday, July 23, 2010 7:13 AM
  • If I change the platform toolset from v100 to v90, I could build the project from within VS 2010 without an error.

    http://msdn.microsoft.com/en-US/library/kyb7zzw4.aspx

    The change from VCBuild to MSBuild seems to cause the errors. :(

    Friday, July 23, 2010 7:33 AM
  • With this information, the "Visual C++ Language" forum maybe better? Is it possible to move this thread, or should I start another one in the other forum?

    Thanks,

    Mike

    Friday, July 23, 2010 10:44 AM
  • At the end, I removed my CFilter class and the filter.cpp and filter.h from the project. After that, I added a new MFC - class with a different name: CFilterDialog and "restore" the code from the old files. And ...

    ... that works. I can compile the complete solution, without any warnings!

     

    But:

    I closed Visual Studio, delete the folder with the project and got the latest version from the Repository. If I look than into the "Externe Abhängigkeiten" (?external depencencies), there is still an entry for a file named filter.h, but this points now to c:\program files\microsoft sdks\windows\v7.0a\include\filter.h ... (and not to "my" file). Maybe there is a problem with the new MSBuild in VS 2010?

    Ciao,

    Mike

    • Marked as answer by mike969 Monday, July 26, 2010 9:54 AM
    Monday, July 26, 2010 9:54 AM
  • Hi Mike,

    I am also facing the below error while migrating my project from VC++ 6.0 to VS 2010. How did you resolve this problem.

    >c:\program files\microsoft visual studio 10.0\vc\atlmfc\include\afxdlgs.h(108): error C2504: 'CDialog' : base class undefined

    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

    Pls help me.

     

    thanks

    Rani

     

    Thursday, May 26, 2011 4:55 PM
  • Hi Rani, do you get the errors also when you change the platfom toolset from v100 to v90? (http://msdn.microsoft.com/en-US/library/kyb7zzw4.aspx) In my case a class CFilter in my project causes the MSBuild error. There is a class CFilter in the WinSDK ... Hope that helps, Mike
    Friday, May 27, 2011 11:27 AM
  • Hi Mike, 

    Yes. I am getting error when I change the platform toolset from V100 to V90. the error is below.

    C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(293,5): error MSB8010: Specified platform toolset (v90) requires Visual Studio 2008. Please make sure that Visual Studio 2008 is installed on the machine.

     

    I am also using CFilter class in project.

     

    I found winSDK in the below path. Filter.h header file is there in the below path.

     

    C:\Program Files\Microsoft SDKs\Windows\v7.1\Include

     

    I specified “C:\Program Files\Microsoft SDKs\Windows\v7.1\Include” path in project setting in Vc++ directories . But still I am getting the same error.

    I could not understand where to specify this path in project settings.

    can you give me the steps to resolve this.

    

    Thanks,

    Rani

     

    

    

     


    Monday, May 30, 2011 6:56 AM
  • Hi Rani,

    I did not change the include path! I renamed my class from CFilter into a different name (cFilterDialog). Have you tried this?

    Ciao,

    Mike

    Monday, May 30, 2011 7:15 AM
  • Hi Mike,

    I tried it. It is compiling fine now.

    Thank you.

    Regards,

    Rani

     

    Wednesday, June 1, 2011 8:27 AM
  • Maybe a couple of years too late but the following worked for me.

    Put the following in the header file

    #include "afxdialogex.h"

    Wednesday, August 29, 2012 12:19 PM