Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem with new operator constructing GDI+ classes

problem with new operator constructing GDI+ classes

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicsannouncementwinforms
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Baris Kurtlutepe
    wrote on last edited by
    #1

    Hi, I'm using GDI+ in my MFC based application and create GDI+ classes on the fly using the new operator as follows: Bitmap* mybitmap = new Bitmap(320,24); The above line compiles fine if I build the application in release mode, but in debug mode, compiler (VC++6.0 w. SP5, latest platform sdk) fails with: error C2660: 'new' : function does not take 3 parameters That is because of mfc's debug definitions on top of the file: #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif and DEBUG_NEW is defined in afx.h as: #define DEBUG_NEW new(THIS_FILE, __LINE__) So, what exactly is wrong with calling a constructor with parameters? Does the "debug" version new operator handle the case incorrect or am I making a terrible mistake somewhere? Any help would be appreciated. P.S: Bitmap(320,200) is the same as Bitmap(320,200,PixelFormat32bppARGB) and neither case it didn't compile.

    J L 2 Replies Last reply
    0
    • B Baris Kurtlutepe

      Hi, I'm using GDI+ in my MFC based application and create GDI+ classes on the fly using the new operator as follows: Bitmap* mybitmap = new Bitmap(320,24); The above line compiles fine if I build the application in release mode, but in debug mode, compiler (VC++6.0 w. SP5, latest platform sdk) fails with: error C2660: 'new' : function does not take 3 parameters That is because of mfc's debug definitions on top of the file: #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif and DEBUG_NEW is defined in afx.h as: #define DEBUG_NEW new(THIS_FILE, __LINE__) So, what exactly is wrong with calling a constructor with parameters? Does the "debug" version new operator handle the case incorrect or am I making a terrible mistake somewhere? Any help would be appreciated. P.S: Bitmap(320,200) is the same as Bitmap(320,200,PixelFormat32bppARGB) and neither case it didn't compile.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      http://www.codeproject.com/vcpp/gdiplus/gdiplusspeed.asp#xx81095xx Read the thread "Can't create bitmaps with new"

      1 Reply Last reply
      0
      • B Baris Kurtlutepe

        Hi, I'm using GDI+ in my MFC based application and create GDI+ classes on the fly using the new operator as follows: Bitmap* mybitmap = new Bitmap(320,24); The above line compiles fine if I build the application in release mode, but in debug mode, compiler (VC++6.0 w. SP5, latest platform sdk) fails with: error C2660: 'new' : function does not take 3 parameters That is because of mfc's debug definitions on top of the file: #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif and DEBUG_NEW is defined in afx.h as: #define DEBUG_NEW new(THIS_FILE, __LINE__) So, what exactly is wrong with calling a constructor with parameters? Does the "debug" version new operator handle the case incorrect or am I making a terrible mistake somewhere? Any help would be appreciated. P.S: Bitmap(320,200) is the same as Bitmap(320,200,PixelFormat32bppARGB) and neither case it didn't compile.

        J Offline
        J Offline
        Joel Lucsy
        wrote on last edited by
        #3

        I found if you comment out the line #define new DEBUG_NEW it will work just fine. You just won't have any indications that you're leaking memory. Joel Lucsy

        B 1 Reply Last reply
        0
        • J Joel Lucsy

          I found if you comment out the line #define new DEBUG_NEW it will work just fine. You just won't have any indications that you're leaking memory. Joel Lucsy

          B Offline
          B Offline
          Baris Kurtlutepe
          wrote on last edited by
          #4

          Thanks for the comments, though I know that it works without defining DEBUG_NEW or with using the new operator from globalnamespace (i.e. ::new) as described in Benjamin's comment, but does anyone have any idea why it doesn't work with GDI+ classes? I mean there must be some error somewhere, since the debug_new operator seems to work fine with classes who take parameters in their constructors but not with GDI+. For example I have created a class with class CTest { public: CTest(); CTest(int x); virtual ~CTest(); }; and it works fine by CTest* test = new CTest(3); and further testing.. tadaa I found the error! :) if your class lacks a constructor without parameters (so do the GDI+ classes), as in: class CTest { public: CTest(int x); virtual ~CTest(); }; the debug new operator fails on the following line: CTest* test = new CTest(3); Must be a bug or a lazy implementation. edit: That wasn't true, I retested it and debug_new works with the CTest class in both cases. I'm pretty confused by now.. :confused:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups