Error c2660: 'gdiplus: gdiplusbase: Operator new': function does not take 3 parameters

Source: Internet
Author: User
Symptom

When we use GDI +, if the program is an MFC program and is in debug mode, we may get the following error message:

Error c2660: 'gdiplus: gdiplusbase: Operator new': function does not take 3 parameters

Cause

In debug mode, the MFC program needs to use a macro definition to extend the new operator so that it needs to accept two additional parameters. These two additional parameters are the source program file name and the code line number. MFC uses them to report Memory leakage information to programmers in debug mode. Because the new operator is overloaded in the MFC class, it can be used with the extended New operator normally. However, non-MFC classes cannot work normally with the new operator of this extension. This is the case with GDI +.

Solution

There are two solutions:

First, comment out the following code to disable the preprocessing command.

# Ifdef _ debug # define new debug_new # endif.

The second method is to allow GDI + to overload the new and delete operators so that they ignore these additional operators. The specific operation is to copy the following code to a header file and include this header file in the project using GDI + instead of gdiplus. h.


/// Ensure that gdiplus header files work properly with MFC debug_new and STL header files.

# Define iterator _ iterator

# Ifdef _ debug

Namespace gdiplus
{
Namespace dllexports
{
# Include "gdiplusmem. H"
};

# Ifndef _ gdiplusbase_h
# DEFINE _ gdiplusbase_h
Class gdiplusbase
{
Public:
Void (operator delete) (void * in_pvoid)
{
Dllexports: gdipfree (in_pvoid );
}

Void * (operator new) (size_t in_size)
{
Return dllexports: gdipalloc (in_size );
}

Void (operator Delete []) (void * in_pvoid)
{
Dllexports: gdipfree (in_pvoid );
}

Void * (operator new []) (size_t in_size)
{
Return dllexports: gdipalloc (in_size );
}

Void * (operator new) (size_t nsize, lpcstr lpszfilename, int nline)
{
Return dllexports: gdipalloc (nsize );
}

Void operator Delete (void * P, lpcstr lpszfilename, int nline)
{
Dllexports: gdipfree (P );
}

};
# Endif // # ifndef _ gdiplusbase_h
}
# Endif // # ifdef _ debug

# Include "gdiplus. H"

# UNDEF iterator

/// Ensure that gdiplus. Lib is linked.
# Pragma comment (Lib, "gdiplus. lib ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.