프로그래밍/버그 & 에러 리포팅

Gdiplus 객체를 new로 생성할 경우 에러 처리

ancdesign 2008. 2. 25. 16:00
MFC에서 Gdiplus를 사용할때 Gdiplus object를 new로 생성할 경우 C2660 에러가 발생함

이는 디버그시 전처리기에서 new 연산자를 재정의 해서 발생되는 문제입니다.

그러므로 전처리기의 재정의를 삭제할 경우 에러가 발생하지 않는다.

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

위의 정의문을 삭제하거나

또는 헤더파일을 수정하여 추가된 파라미터를 무시하도록 재정의 하는 방법입니다.


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


* 첨부된 파일 "GdiplusH.h"를 다운 받아서 inlcude 하여 사용하면 된다.




참고 사이트 : http://support.microsoft.com/kb/317799