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 ")