locked
c2065 CDC Undeclared identifier RRS feed

  • Question

  • Hi!

    While compiling my code I get the C2065 error undeclared identifier point at CDC.


    	// Create a memory DC compatible with the display
    	CDC sourceDC, destDC;
    	sourceDC.CreateCompatibleDC( NULL );
    	destDC.CreateCompatibleDC( NULL );
    
    This is the way it is written HERE :

    http://msdn.microsoft.com/en-us/library/kwxzck32(VS.80).aspx

    Can anybody help me why it is so? What should I do to solve the error?

    Thanks for your feedbacks.

    My best,
    yashar
    Wednesday, August 19, 2009 8:51 AM

Answers

  • Did you create an MFC project? You can find this out via Right click on your project -> Properties -> General -> User of MFC.

    Your stdafx.h should have this include:

    #include <afxwin.h> // MFC core and standard components


    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
    • Proposed as answer by Geert van Horrik Wednesday, August 19, 2009 7:29 PM
    • Marked as answer by yade Thursday, August 20, 2009 8:28 AM
    Wednesday, August 19, 2009 9:14 AM
  • It seems like you are trying to use MFC classes in a non-MFC project.  Instead of trying to fix various settings it would be much better to start over to make sure everything is properly set up.  Select "MFC Application" when you generate the new project template.
    • Proposed as answer by Geert van Horrik Wednesday, August 19, 2009 7:30 PM
    • Marked as answer by yade Thursday, August 20, 2009 8:28 AM
    Wednesday, August 19, 2009 1:20 PM
  • ...or just use HDC and ::CreateCompatibleDC() instead. CDC is a pretty thin wrapper.
    • Proposed as answer by Geert van Horrik Wednesday, August 19, 2009 7:29 PM
    • Marked as answer by yade Thursday, August 20, 2009 8:28 AM
    Wednesday, August 19, 2009 4:19 PM

All replies

  • CDC is an MFC class.

    Did you include "stdafx.h", or is your application even set to use MFC?
    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
    Wednesday, August 19, 2009 9:04 AM
  • Yes Geert.

    "stdafx.h" is included in my code. How can set to use that class?
    Wednesday, August 19, 2009 9:09 AM
  • Did you create an MFC project? You can find this out via Right click on your project -> Properties -> General -> User of MFC.

    Your stdafx.h should have this include:

    #include <afxwin.h> // MFC core and standard components


    Geert van Horrik - CatenaLogic
    Visit my blog: http://blog.catenalogic.com

    Looking for a way to deploy your updates to all your clients? Try Updater!
    • Proposed as answer by Geert van Horrik Wednesday, August 19, 2009 7:29 PM
    • Marked as answer by yade Thursday, August 20, 2009 8:28 AM
    Wednesday, August 19, 2009 9:14 AM
  • It seems like you are trying to use MFC classes in a non-MFC project.  Instead of trying to fix various settings it would be much better to start over to make sure everything is properly set up.  Select "MFC Application" when you generate the new project template.
    • Proposed as answer by Geert van Horrik Wednesday, August 19, 2009 7:30 PM
    • Marked as answer by yade Thursday, August 20, 2009 8:28 AM
    Wednesday, August 19, 2009 1:20 PM
  • ...or just use HDC and ::CreateCompatibleDC() instead. CDC is a pretty thin wrapper.
    • Proposed as answer by Geert van Horrik Wednesday, August 19, 2009 7:29 PM
    • Marked as answer by yade Thursday, August 20, 2009 8:28 AM
    Wednesday, August 19, 2009 4:19 PM
  • Thanks guys.

    All tips are useful !
    Wednesday, August 19, 2009 4:26 PM