VC6的Bug吗, 各位高手进来看看

sheds 2008-03-06 01:56:03
有二个类
类A
class A
{
B m_mem;
UINT aa;
}

class B
{
...
UINT cc;
}

在这样的情况下尽然出现了在类A中为aa赋值时, 覆盖了cc的值
如果cc是一个指针,结果那就是程序异常

请问高手,产生这问题的原因是什么呢,编译器问题吗?
...全文
317 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
scq2099yt 2008-03-06
  • 打赏
  • 举报
回复
ding
sheds 2008-03-06
  • 打赏
  • 举报
回复
在CBarChart类内Sizeof结果是0x280
在DlgLog类内Sizeof的结果却是0x26C

是什么原因呢
sheds 2008-03-06
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 aspnetwuxueyou 的回复:]
到www.devdiv.net上把代码附上,我保证给你解决问题
[/Quote]

代码不能公开,抱歉.就看上面的头文件定义帮看看吧
sheds 2008-03-06
  • 打赏
  • 举报
回复
我的代码都是在同一个工程中的
vcPlayer 2008-03-06
  • 打赏
  • 举报
回复
这种情况较多出现于类B的定义与使用不在同一工程,因头文件定义上的疏忽造成。

// 这是你的当前工程中的定义:
class A
{
B m_mem;
UINT aa;
}

class B
{
...
// UINT cc; 没有这个了.此时编译器按照这个定义来分配内在空间,那么A::aa的位置就放在B::cc上了。
}



// 这是在另一个工程中(比如一个导出类B的DLL工程)的定义:
class B
{
...
UINT cc;
}
ouyh12345 2008-03-06
  • 打赏
  • 举报
回复
要缩小范围
去掉mfc之类的东西,弄2个简单的类,然后在console下运行
wawaku 2008-03-06
  • 打赏
  • 举报
回复
LS 又搞推销。。。。
sheds 2008-03-06
  • 打赏
  • 举报
回复
分不够,偶继续加,找出原因为止
sheds 2008-03-06
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 akirya 的回复:]
是啊,这个在后来的版本还有bug。
vs2005的时候也碰到过比较奇怪的现象。
[/Quote]

不是嵌套类的问题,我把类放到外面也一样的
是类大小计算的不对
sheds 2008-03-06
  • 打赏
  • 举报
回复
我经过反复试验,感觉问题出在VC6没有算出正确的CBarChart的大小,实际占用的字节数,比VC算出来的要多
因此放他后面的类成员变量的成员值会覆盖他的

是什么样的类会引起VC计算大小不正确呢
是CObArray吗
  • 打赏
  • 举报
回复
是啊,这个在后来的版本还有bug。
vs2005的时候也碰到过比较奇怪的现象。
my_girlf 2008-03-06
  • 打赏
  • 举报
回复
LZ,你发这么多代码,还不如把源程序附上吧。下下来还可以调试,才能知道出错的真正原因。如果你的主程序不宜公开,你用这些类做个简单一点的Demo,大家来学习学习。
sheds 2008-03-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 akirya 的回复:]
记得VC6对局部类支持有限。
[/Quote]

你指的是什么呢,嵌套类的定义吗?
sheds 2008-03-06
  • 打赏
  • 举报
回复
我是经过VC调试,汇编级调试定位到这里的
对话框一起动,作为局部变量的主对话框他的在栈中的地址就应该确定了
主对话框他的类成员变量,地址也应该就确定了.
可是在经过层层构造后.
最后在主对话框中对自己的成员变量赋值时,他的类成员变量 的成员值居然这时候被覆盖了

感觉很是神奇,没有想明白, 除非哪个类成员的大小会动态变化
  • 打赏
  • 举报
回复
记得VC6对局部类支持有限。
zhucde 2008-03-06
  • 打赏
  • 举报
回复
靠,这么完整的代码。看的眼花,仅看到这里:
class CBarChart : public CWnd, CChartGCalc
{
// Construction
public:
CBarChart();

// Operations
protected:

/*----------------------------------------------------------*
¦ CChartData Class ¦
¦ ¦
¦ Holds data of a chart and let the chart to do ¦
¦ reqauered operations on it ¦
¦ ¦
*----------------------------------------------------------*/
class CChartData
{
struct data
{
CString m_szLabel;
double m_udValue;
COLORREF m_color;
};


。。。。。。

难道是我真的眼花,类的嵌套定义?

楼主直接写出出错的两个类以前两个类哪里进行赋值的即可,贴这么多没用的,看的确实眼花
sheds 2008-03-06
  • 打赏
  • 举报
回复
代码结构如上, 请大家帮分析下问题出在哪里
sheds 2008-03-06
  • 打赏
  • 举报
回复
class CBarChart : public CWnd, CChartGCalc
{
// Construction
public:
CBarChart();

// Operations
protected:

/*----------------------------------------------------------*
| CChartData Class |
| |
| Holds data of a chart and let the chart to do |
| reqauered operations on it |
| |
*----------------------------------------------------------*/
class CChartData
{
struct data
{
CString m_szLabel;
double m_udValue;
COLORREF m_color;
};

struct SerialData
{
COLORREF color;
CObArray* p_arr;
CString szLabel;
};

CObArray m_SerialArr;
int m_SerialNums;

double m_udMax;

protected:
void CalculateMaximum();

public:
CChartData();
...功能函数
}; // end of CChartData

/*-----------------------------------------------------------*
| CGDIGrid Class |
| |
| Draws a grid behind the chart. |
| UNDONE: The grid class should act better. instead of |
| drawing horizontal lines from top, it should start |
| from the line under the bars. (Logical y = 0 axe) |
| |
*-----------------------------------------------------------*/
class CGDIGrid
{
protected:
// Attributes
UINT m_nVLineCount,
m_nHLineCount,
m_nFixedSize;

double m_fVMax;
double m_fVStartValue;
UINT m_nHStep;

BOOL m_bShowDial;

CPen m_penGrid,
*m_pPenOld;

int m_nVGapSize,
m_nHGapSize;
public:
// Construction
CGDIGrid();
~CGDIGrid();

...功能函数
}; // end of CGDIGrid


class CChartDraw : public CChartGCalc
{
protected:
CChartData m_chartData;

double m_dAlpha, m_dIndex;

COLORREF m_colorChartBK;

CFont m_font, *m_pFontOld;
LOGFONT m_lf;

double m_rMargin;

double m_udMaxDial;

UINT m_nAxisHeight;
public:
CChartDraw();
~CChartDraw();

virtual void CreateLabelFont();

BOOL IsLabelVisible();

virtual void DisplayToolTip(CPoint& point, CRect& rcBound,
CRect& rcMemPic, BOOL bScale, CString& szTip) = 0;

...功能函数

void Draw(CDC* pDC, CRect& rcBound);
};

/*-----------------------------------------------------------*
| CChartBar Class |
| |
| This class is responsible for for drawing bars and |
| performing required calculation for the job. |
| |
*-----------------------------------------------------------*/
class CChartBar : public CChartDraw
{
protected:
CSize m_sBarPicSize;

BOOL m_bSingleBar;
BOOL m_bShowLabel,
m_bShowBarText;

int m_nBarTextType;
int m_nBarWidth, m_nBarGap;

double m_fBarGroupWidth;

void DrawBar(CDC* pDC, CRect rcBound, COLORREF BarColor, COLORREF colorChartBK);
void DrawBars(CDC* pDC, CRect& rcBound);

void CalcBarsSize();
void CalcBarGap(CRect& rcBound);

public:
BOOL IsLabelVisible();

void DisplayToolTip(CPoint& point, CRect& rcBound,
CRect& rcMemPic, BOOL bScale, CString& szTip);

CChartBar();
~CChartBar();

...功能函数
};

/*----------------------------------------------------------*
| CChartPrinter Class |
| |
| No need to description(!) This class should print the|
| Chart using print dialog. |
| |
*----------------------------------------------------------*/
class CChartPrinter : public CChartGCalc
{
protected:
CDC *m_pMemDC;
CRect m_rcMemPic;
CBitmap *m_pBmpMem;

BOOL m_bScale;

void OnPrint (CDC *pDC, CPrintInfo* pInfo);
void OnPrintCompatible (CDC *pDC, CPrintInfo* pInfo);

//HANDLE DDBToDIB( CBitmap* bitmap, DWORD dwCompression, CPalette* pPal );
public:
void Print(CDC* pDC, CDC *pMemDC, CBitmap* pBmp,
CString szTitle, CRect& rcMemPic, BOOL bFit, BOOL bCompatible);
};

// Attributes
protected:
COLORREF m_colorBK;
CRect m_rctClient;
CBrush m_brFrame;
CGDIGrid m_grid;

BOOL m_bShowGrid,
m_bAutoScale,
m_bShowTip;

CChartBar
m_bars;

CDC m_dcMem;

CBitmap *m_pBmpBars,
*m_pBmpOld;

CRect m_rctMemPic;
CRect m_rectBroder;

CChartPrinter
m_printer;

CString m_szTitle,
m_szTip;

CChartTip
m_toolTip;

CString m_szLastErr;

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBarChart)
//}}AFX_VIRTUAL

// Implementation
protected:

...功能函数

public:
...功能函数
virtual ~CBarChart();

void StartDraw();
// Generated message map functions
protected:
//{{AFX_MSG(CBarChart)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
sheds 2008-03-06
  • 打赏
  • 举报
回复
CSerDlg::CSerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginServerDlg)
m_bAutoStart = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); //执行这一句时, m_DlgLog.m_chart.m_tooltip. m_rgnTip, 被覆盖

m_nSerLogMask = 0;
}

class CSerDlg : public CDialog
{
// Construction
public:
CSerDlg (CWnd* pParent = NULL); // standard constructor

void AddLogStr(CString NoteMsg);
void AddNoteStr(DWORD SoftId, CString NoteMsg);

void SetRunInfo(int type, CString strNote);

// Dialog Data
//{{AFX_DATA(CSerDlg)
enum { IDD = IDD_LOGINSERVER_DIALOG };
CEdit m_editSerRunTime;
CXTabCtrl m_TabCtrl;
CButton m_btnStartSer;
BOOL m_bAutoStart;

//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSerDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

public:
CMySer m_IOSer;
CNoteRes m_NoteRes;

DWORD m_nServerLoginMask;

CDlgNetLog m_DlgNetLog;
CDlgLog m_DlgLog;


// Implementation
protected:
HICON m_hIcon;

static UINT SerThread( LPVOID pParam );

void InitTab();

// Generated message map functions
//{{AFX_MSG(CLoginServerDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnOK();
afx_msg void OnCancel();
afx_msg void OnClose();
afx_msg void OnExit();
afx_msg void OnCheckAutostart();
afx_msg void OnDestroy();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

class CDlgLog : public CDialog
{
// Construction
public:
CDlgLog(CWnd* pParent = NULL); // standard constructor

// Dialog Data
//{{AFX_DATA(CDlgLog)
enum { IDD = IDD_DLG_LOGCOUNT };
//}}AFX_DATA


// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlgLog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
public:
CShowLog m_ShowLog;
CBarChart m_chart;

protected:

// Generated message map functions
//{{AFX_MSG(CDlgLog)
virtual BOOL OnInitDialog();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnBtnRefresh();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

///////////////////////////////////////////////////////////////////////
// CChartGCalc Class
//
//
// A set of handy GDI functions for manipulating
// pixel colors, etc.
//
///////////////////////////////////////////////////////////////////////
class CChartGCalc
{
protected:
UINT GABS (const int& nmbr);
COLORREF DifColor(COLORREF color, UINT nDist);
COLORREF OrColor(COLORREF colFore, COLORREF colBK, UINT nForePercent);

// Refer to the following article in 'CodeProject.com' By 'Roger Allen'
// 'Printing tips and tricks from the trenches'
// And goto topic: 'Use DIB's instead of DDB's'
HANDLE DDBToDIB( CBitmap* bitmap, DWORD dwCompression, CPalette* pPal );
}; // end of GDICalc


///////////////////////////////////////////////////////////////////////
// CChartTip Class
//
//
// Adds tooltip capabilities for bar chart.
// Tooltip should show: value, Label and percentage
//
///////////////////////////////////////////////////////////////////////
class CChartTip : public CWnd, CChartGCalc
{
// Construction
public:
CChartTip();

// Attributes
public:

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CChartTip)
//}}AFX_VIRTUAL

// Implementation
public:
void Hide();
void Pop();
BOOL Create(CWnd* pParentWnd, BOOL* pbEnable, CString* lpszTitle, int nDelay);
virtual ~CChartTip();

// Generated message map functions
protected:
static LPCTSTR m_lpszClass;
BOOL *m_pbEnable,
m_bTimer;
CString *m_lpszTitle,
m_szText,
m_szOldTitle;
CPoint m_pointOld;
int m_nDelay;
CRect m_rcClient;
CBrush m_brFrame,
m_brBK,
m_brShadow;
CFont m_fontBold,
m_fontNorm;

CRgn m_rgnTip, m_rgnCopy, m_rgnShadow;

//{{AFX_MSG(CChartTip)
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
void HideWindow();

};
guanghong 2008-03-06
  • 打赏
  • 举报
回复
[Quote=引用楼主 sheds 的帖子:]
有二个类
类A
class A
{
B m_mem;
UINT aa;
}

class B
{
...
UINT cc;
}

在这样的情况下尽然出现了在类A中为aa赋值时, 覆盖了cc的值
如果cc是一个指针,结果那就是程序异常

请问高手,产生这问题的原因是什么呢,编译器问题吗?
[/Quote]

没有覆盖cc啊,你哪里弄错了吧
不可能啦!
加载更多回复(3)

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧