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. error C2660: 'new' : function does not take 3 parameters

error C2660: 'new' : function does not take 3 parameters

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
6 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.
  • C Offline
    C Offline
    Crystal
    wrote on last edited by
    #1

    Can anybody tell me why I am getting this error for the following line: graphics = new Graphics(hdcPrint); For your information, this is my function: // this function is for OTCDialog: OK button // It uses GDI to send image to a printer void OTRDialog::OnPrintFrom() { DWORD size; HDC hdcPrint; DOCINFO docInfo; ZeroMemory(&docInfo, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = "GdiplusPrint"; // Create a PRINTDLG structure, and initialize the appropriate fields. PRINTDLG printDlg; ZeroMemory(&printDlg, sizeof(PRINTDLG)); printDlg.lStructSize = sizeof(PRINTDLG); printDlg.Flags = PD_RETURNDC; // Display a print dialog box. if(!PrintDlg(&printDlg)) { printf("Failure\n"); } else { // Now that PrintDlg has returned, a device context handle // for the chosen printer is in printDlg->hDC. StartDoc(hdcPrint, &docInfo); Graphics* graphics; StartPage(hdcPrint); graphics = new Graphics(hdcPrint); Image image(L"My_report.bmp"); graphics.DrawImage(&image, 5, 0, 360, 410); // Create a string. WCHAR string[256]; wcscpy(string, L"Sample Text"); // Initialize arguments. Font myFont(L"Arial", 6); PointF origin(20.0f, 5.0f); SolidBrush blackBrush(Color(255, 0, 0, 0)); // Draw string. graphics.DrawString(string, wcslen(string), &myFont, origin, &blackBrush); delete graphics; EndPage(hdcPrint); EndDoc(hdcPrint); DeleteDC(hdcPrint); } if(printDlg.hDevMode) GlobalFree(printDlg.hDevMode); if(printDlg.hDevNames) GlobalFree(printDlg.hDevNames); if(printDlg.hDC) DeleteDC(printDlg.hDC); }

    E C 3 Replies Last reply
    0
    • C Crystal

      Can anybody tell me why I am getting this error for the following line: graphics = new Graphics(hdcPrint); For your information, this is my function: // this function is for OTCDialog: OK button // It uses GDI to send image to a printer void OTRDialog::OnPrintFrom() { DWORD size; HDC hdcPrint; DOCINFO docInfo; ZeroMemory(&docInfo, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = "GdiplusPrint"; // Create a PRINTDLG structure, and initialize the appropriate fields. PRINTDLG printDlg; ZeroMemory(&printDlg, sizeof(PRINTDLG)); printDlg.lStructSize = sizeof(PRINTDLG); printDlg.Flags = PD_RETURNDC; // Display a print dialog box. if(!PrintDlg(&printDlg)) { printf("Failure\n"); } else { // Now that PrintDlg has returned, a device context handle // for the chosen printer is in printDlg->hDC. StartDoc(hdcPrint, &docInfo); Graphics* graphics; StartPage(hdcPrint); graphics = new Graphics(hdcPrint); Image image(L"My_report.bmp"); graphics.DrawImage(&image, 5, 0, 360, 410); // Create a string. WCHAR string[256]; wcscpy(string, L"Sample Text"); // Initialize arguments. Font myFont(L"Arial", 6); PointF origin(20.0f, 5.0f); SolidBrush blackBrush(Color(255, 0, 0, 0)); // Draw string. graphics.DrawString(string, wcslen(string), &myFont, origin, &blackBrush); delete graphics; EndPage(hdcPrint); EndDoc(hdcPrint); DeleteDC(hdcPrint); } if(printDlg.hDevMode) GlobalFree(printDlg.hDevMode); if(printDlg.hDevNames) GlobalFree(printDlg.hDevNames); if(printDlg.hDC) DeleteDC(printDlg.hDC); }

      E Offline
      E Offline
      Ed Gadziemski
      wrote on last edited by
      #2

      How many parameters does the constructor for Graphics take? Sounds like your giving it less than the number required.

      C 1 Reply Last reply
      0
      • E Ed Gadziemski

        How many parameters does the constructor for Graphics take? Sounds like your giving it less than the number required.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        It takes exactly what she is giving it - a HDC. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

        E 1 Reply Last reply
        0
        • C Crystal

          Can anybody tell me why I am getting this error for the following line: graphics = new Graphics(hdcPrint); For your information, this is my function: // this function is for OTCDialog: OK button // It uses GDI to send image to a printer void OTRDialog::OnPrintFrom() { DWORD size; HDC hdcPrint; DOCINFO docInfo; ZeroMemory(&docInfo, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = "GdiplusPrint"; // Create a PRINTDLG structure, and initialize the appropriate fields. PRINTDLG printDlg; ZeroMemory(&printDlg, sizeof(PRINTDLG)); printDlg.lStructSize = sizeof(PRINTDLG); printDlg.Flags = PD_RETURNDC; // Display a print dialog box. if(!PrintDlg(&printDlg)) { printf("Failure\n"); } else { // Now that PrintDlg has returned, a device context handle // for the chosen printer is in printDlg->hDC. StartDoc(hdcPrint, &docInfo); Graphics* graphics; StartPage(hdcPrint); graphics = new Graphics(hdcPrint); Image image(L"My_report.bmp"); graphics.DrawImage(&image, 5, 0, 360, 410); // Create a string. WCHAR string[256]; wcscpy(string, L"Sample Text"); // Initialize arguments. Font myFont(L"Arial", 6); PointF origin(20.0f, 5.0f); SolidBrush blackBrush(Color(255, 0, 0, 0)); // Draw string. graphics.DrawString(string, wcslen(string), &myFont, origin, &blackBrush); delete graphics; EndPage(hdcPrint); EndDoc(hdcPrint); DeleteDC(hdcPrint); } if(printDlg.hDevMode) GlobalFree(printDlg.hDevMode); if(printDlg.hDevNames) GlobalFree(printDlg.hDevNames); if(printDlg.hDC) DeleteDC(printDlg.hDC); }

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          1. Why does graphics have to be a pointer ? I seem to recall GDI+ does not like having new called on things in C++ ( new in C# is a totally different beast ), because it forces you to use it's .Clone methods instead. 2. Once you fix this, you'll get errors because you're using the . instead of the -> for the graphics object ( as it's a pointer ). Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

          1 Reply Last reply
          0
          • C Christian Graus

            It takes exactly what she is giving it - a HDC. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

            E Offline
            E Offline
            Ed Gadziemski
            wrote on last edited by
            #5

            DEBUG_NEW defines a new operator that takes three parameters to catch memory leaks when _DEBUG is also defined. Redefine it to use the non-debug new. Or, use the scope resolution operator ( :: ) before new to use the default C++ version.

            1 Reply Last reply
            0
            • C Crystal

              Can anybody tell me why I am getting this error for the following line: graphics = new Graphics(hdcPrint); For your information, this is my function: // this function is for OTCDialog: OK button // It uses GDI to send image to a printer void OTRDialog::OnPrintFrom() { DWORD size; HDC hdcPrint; DOCINFO docInfo; ZeroMemory(&docInfo, sizeof(DOCINFO)); docInfo.cbSize = sizeof(DOCINFO); docInfo.lpszDocName = "GdiplusPrint"; // Create a PRINTDLG structure, and initialize the appropriate fields. PRINTDLG printDlg; ZeroMemory(&printDlg, sizeof(PRINTDLG)); printDlg.lStructSize = sizeof(PRINTDLG); printDlg.Flags = PD_RETURNDC; // Display a print dialog box. if(!PrintDlg(&printDlg)) { printf("Failure\n"); } else { // Now that PrintDlg has returned, a device context handle // for the chosen printer is in printDlg->hDC. StartDoc(hdcPrint, &docInfo); Graphics* graphics; StartPage(hdcPrint); graphics = new Graphics(hdcPrint); Image image(L"My_report.bmp"); graphics.DrawImage(&image, 5, 0, 360, 410); // Create a string. WCHAR string[256]; wcscpy(string, L"Sample Text"); // Initialize arguments. Font myFont(L"Arial", 6); PointF origin(20.0f, 5.0f); SolidBrush blackBrush(Color(255, 0, 0, 0)); // Draw string. graphics.DrawString(string, wcslen(string), &myFont, origin, &blackBrush); delete graphics; EndPage(hdcPrint); EndDoc(hdcPrint); DeleteDC(hdcPrint); } if(printDlg.hDevMode) GlobalFree(printDlg.hDevMode); if(printDlg.hDevNames) GlobalFree(printDlg.hDevNames); if(printDlg.hDC) DeleteDC(printDlg.hDC); }

              E Offline
              E Offline
              Ed Gadziemski
              wrote on last edited by
              #6

              Try this: graphics = ::new Graphics(hdcPrint); The problem is that an MFC generated define, DEBUG_NEW, defines a "new" operator that takes three parameters. It only applies for a debug build; if you do a release build your program should work. You can undefine DEBUG_NEW so that debug builds also work. Or, as shown in the example code above, you can use the scope resolution operator ( :: ) before new to use the default C++ version.

              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