Hey.. We have a class :
class CGlueImage : public CObject
{
DECLARE_DYNCREATE(CGlueImage)
// Attributes
public:
CGlueImage();
CGlueImage(CString navn, int id);
// Operations
public:
CString GetGlueName();
int GetGlueId();
CRect GetRect();
void DrawDragImage(CDC* pDC, POINT point);
void DrawHover(CDC *pDC, POINT point);
BOOL PtInImage(POINT point);
UINT GetWidth();
void SetWidth(UINT width);
void Draw(CDC *pDC, int x, int y);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGlueImage)
//}}AFX_VIRTUAL
CGlueImage& operator=(const CGlueImage& rhs)
{
m_color = RGB(GetRValue(rhs.m_color), GetGValue(rhs.m_color),
GetBValue(rhs.m_color));
m_glueRect = CRect(rhs.m_glueRect.TopLeft(),
rhs.m_glueRect.BottomRight());
m_nGlueHeight = rhs.m_nGlueHeight;
m_nGlueId = rhs.m_nGlueId;
m_sGlueName = rhs.m_sGlueName;
return *this;
}
CGlueImage(const CGlueImage& rhs)
{
m_color = rhs.m_color;
m_glueRect = rhs.m_glueRect;
m_nGlueHeight = rhs.m_nGlueHeight;
m_nGlueId = rhs.m_nGlueId;
m_sGlueName = rhs.m_sGlueName;
}
~CGlueImage();
// Implementation
protected:
COLORREF m_color;
CRect m_glueRect;
UINT m_nGlueHeight;
int m_nGlueId;
CString m_sGlueName;
// Generated message map functions
//{{AFX_MSG(CGlueImage)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
Quote:
};
In our View we have :
std::vector<CGlueImage> m_glueList;
and a method :
void CGlueView::AddImage(CString name, int id)
{
CGlueImage gi(name, id);
m_glueList.push_back(gi);
Invalidate();
Quote:
}
What we are trying to do is use the AddImage method in the documents
OnNewDocument method:
CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->GetMainWnd() ;
CGlueView* pGlueView =
(CGlueView*)pMainFrame->m_wndGlueBar.GetRuntimeClass();
pGlueView->AddImage("NADA", 0);
But when we try to make a new document in our program (aka OnNewDocument()
is run) this happens :
Unhandled exception in Program.exe (MFC42D.DLL) : 0xC000005 : Acces
Violation.
Cotext i de{*filter*} :
CObject::CObject()
CGlueImage::CGlueImage(const CGlueImage &)
std::_Construct(CGlueImage *, const CGlueImage &)
std::allocator<CGlueImage>::construct(CGlueImage *, const CGlueImage &)
std::vector<CGlueImage, std::allocator<CGlueImage> >::_Ufill(CGlueImage *,
unsigned int, const CGlueImage &)
std::vector>CGlueImage, std::allocator<CGlueImage> >::insert(CGlueImage *,
unsigned int, const CGlueImage &)
std::vector<CGlueImage, std::allocator<CGlueImage> >::insert(CGlueImage*,
const CGlueImage &)
std::vector<CGlueImage, std::allocator<CGlueImage> >::push_back(const
CGlueImage&)
CGlueView::AddImage(CString, int)
It seems like theres a problem with CGlueImages copy constructor, but what ?
I spent last night trying all sorts of ideas I could come up with, but now
Im lost.
I hope someone here have some ideas of what could cause this problem.
Cheers.
Thomas Ree Hjelm