GdiplusNew.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //// Ensure that GdiPlus header files work properly with MFC DEBUG_NEW and STL header files.
  2. /*
  3. PRB: Microsoft Foundation Classes DEBUG_NEW Does Not Work with GDI+
  4. SYMPTOMS:
  5. When you build a debug version of a Microsoft Foundation Classes (MFC) application that uses GDI+,
  6. you may receive an error message that resembles the following:
  7. error C2660: 'Gdiplus::GdiplusBase::operator new' : function does not take 3 parameters
  8. CAUSE:
  9. In debug builds, MFC defines a preprocessor macro that expands the new operator to an overloaded new operator
  10. that takes two extra parameters. The extra parameters are the source file name and code line number.
  11. MFC can use this information to report memory leaks to the programmer when in debug mode.
  12. This works for MFC classes because MFC provides overloads for new that accept the extra parameters.
  13. However, because this expansion is done by the preprocessor, it affects all usage of the new operator.
  14. If any non-MFC classes are used in the project, their new operator is also expanded, even if no suitable overload
  15. of new is available in that class. This is what happens in GDI+, and as a result, you receive a compile-time error message.
  16. */
  17. #pragma once
  18. #define iterator _iterator
  19. #ifdef _DEBUG
  20. namespace Gdiplus
  21. {
  22. namespace DllExports
  23. {
  24. #include "GdiplusMem.h"
  25. };
  26. #ifndef _GDIPLUSBASE_H
  27. #define _GDIPLUSBASE_H
  28. class GdiplusBase
  29. {
  30. public:
  31. void (operator delete)(void* in_pVoid)
  32. {
  33. DllExports::GdipFree(in_pVoid);
  34. }
  35. void* (operator new)(size_t in_size)
  36. {
  37. return DllExports::GdipAlloc(in_size);
  38. }
  39. void (operator delete[])(void* in_pVoid)
  40. {
  41. DllExports::GdipFree(in_pVoid);
  42. }
  43. void* (operator new[])(size_t in_size)
  44. {
  45. return DllExports::GdipAlloc(in_size);
  46. }
  47. void * (operator new)(size_t nSize, LPCSTR lpszFileName, int nLine)
  48. {
  49. return DllExports::GdipAlloc(nSize);
  50. }
  51. void operator delete(void* p, LPCSTR lpszFileName, int nLine)
  52. {
  53. DllExports::GdipFree(p);
  54. }
  55. };
  56. #endif // #ifndef _GDIPLUSBASE_H
  57. }
  58. #endif // #ifdef _DEBUG
  59. #include "gdiplus.h"
  60. #undef iterator
  61. //// Ensure that Gdiplus.lib is linked.
  62. #pragma comment(lib, "gdiplus.lib")