VC++6.0下,GDI+对话框工程,从Image派生新类ImageEx,有一个构造函数ImageEx::ImageEx(LPCTSTR sResourceType, LPCTSTR sResource),在对话框类中添加变量:ImageEx* m_image,然后在OnInitDialog()函数中用如下代码:
  m_image = new ImageEx("gif","smile");
最后的程序在Release模式下编译、运行无误,但在Debug模式下就会在上面的代码处报告错误:
  error C2660: 'new' : function does not take 3 parameters
研究了几天了,实在弄不明白完全一样的代码,在两种模式下会有这样的区别?在Debug下这多出来的第三个参数是什么?请各位帮忙解释一下!谢谢了!!

解决方案 »

  1.   

    我告诉你正确答案, 在出错地方的cpp文件, 删除#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif给分吧..哈哈
      

  2.   

    To 楼上striking(硬撑者)朋友:
      感谢参与,删去那几行后再编译,涛声依旧^_^
      

  3.   

    试试. cpp前加加上
     #if defined( _DEBUG )
       #undef new
       #endif不行的 话,试试
    在stdafx.h添加
    #define iterator _iterator#ifdef _DEBUGnamespace Gdiplus
    {
    namespace DllExports
    {
    #include 
    };#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 
    using namespace Gdiplus;
    #undef iterator===最后还是不行的话, 参考http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_new_Operator.asp
      

  4.   

    ImageEx的构造函数声明:
    ImageEx(IN LPCTSTR  sResourceType, IN LPCTSTR  sResource); 
    不知道这个“IN”是什么意思,有没有它们没区别。
      

  5.   

    贴上ImageEx类的一些代码:
    class ImageEx : public Image
    {
    public:
    ImageEx(IN LPCTSTR  sResourceType,IN LPCTSTR  sResource);
    ImageEx(const WCHAR* filename, BOOL useEmbeddedColorManagement = FALSE);
    ~ImageEx();
    ......};To striking(硬撑者)朋友:
      分别加入你给的几段代码后,Rebuild all还是没有用。
      

  6.   

    那时因为debug版本中的new 被一个宏重新定义过了.
      

  7.   

    经楼上hdqqq(小西瓜)朋友提醒,我查了Image类的基类GdiplusBase,全部代码如下:#ifndef _GDIPLUSBASE_H
    #define _GDIPLUSBASE_Hclass 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);
        }
    };#endif
    -----------------------------------------------------------
    的确,new和new[]关键字是被它的基类重载过了,并且只能有一个参数size_t in_size。只是不明白为什么Release下,我的代码又没问题呢?难道这时不管基类中的重载吗?
      

  8.   

    再次仔细研究striking(硬撑者)朋友最初给的方法的背后,我在Afx.h文件中找到如下两行:void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
    #define DEBUG_NEW new(THIS_FILE, __LINE__)再加上系统自动生成的下面两行:#ifdef _DEBUG
    #define new DEBUG_NEW即Debug下系统调用new的时候果然不是听从基类GdiplusBase中new的,而是Afx.h中那里的new(这时的确有三个参数),按理系统编译到这里应该提示出错在这行:
    void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
    但它下面这行代码:#define DEBUG_NEW new(THIS_FILE, __LINE__)使得出错行提示又在我的代码中调用new的这行:
    m_image = new ImageEx("gif","smile");
    让我误会,以为系统把这行当成三个参数了。
      

  9.   

    删去下面几行:
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    系统编译时报告的错误是:
    gdiplus.lib(imagingguds.obj) : fatal error LNK1103: debugging information corrupt; recompile module
      

  10.   

    试试给 Visual Studio 6.0 打补丁:下载 vs6sp5 或者 vs6sp6。http://www.microsoft.com/downloads/details.aspx?familyid=A8494EDB-2E89-4676-A16A-5C5477CB9713&displaylang=en就算是这个问题没有解决,打打补丁也是好的。
      

  11.   

    顶一下,发现很多下载的用Gdi+的例子在Debug下都有下面这样的错误:
    gdiplus.lib(imagingguds.obj) : fatal error LNK1103: debugging information corrupt; recompile module
      

  12.   

    最后顶一下,能解决上面这个Debug下的错误的朋友,我另外在基础版开贴给分,请大家帮忙啊!
      

  13.   

    有没有将gdi+的include路径放到最前?
      

  14.   

    实在是晕,后来查了资料,
    Linking...
       Creating library Debug/xxx.lib and object Debug/xxx.exp
    uuid.lib(comcat.obj) : fatal error LNK1103: debugging information corrupt; recompile module
    Error executing link.exe.出现环境 xp sp2 + 最新 sdk + vc6 +vc7出现此错误 位 vc6 下编译,问题出来 lib 和 link.exe 版本不合
    查看 lib 设置,将 sdk 移动到最后, 
    编译通过。看来 xp 的 sdk 已经默认的向 vc.net 靠拢了
      

  15.   

    基于上面的说明, 我认为是新的sdk在搞鬼, 后来我换到旧的sdk 就通过了. 新的sdk是采用vs7编译的, 所以vc6无法兼容, 所以需要换到旧的sdk. 以编译通过.
      

  16.   

    特别感谢striking(硬撑者)朋友的分析和测试!我手中没有vc.net,也没有以前的sdk,目前看来只能这样了。很早以前就听说新的sdk不支持vc6了,看来此言非虚。结贴了,也谢谢其他朋友的捧场!!
      

  17.   

    To striking(硬撑者 [email protected])朋友:
      
      感谢你对本贴的热心回复,给了我很大的帮助!这个ID没什么分了,这两天才积了一些,我把分加在我以前在基础版开出的一个问题贴中(已经自己解决了),一点心意,请笑纳!!烦请到该贴留个脚印,不胜感激!!http://community.csdn.net/Expert/topic/4550/4550104.xml?temp=.867016