I am trying to create my own listbox class but failed. Here is the source code:
// MyListBox.h
// MyListBox.cppCode:class CMyListBox : public CListBox { DECLARE_DYNAMIC(CMyListBox) public: CMyListBox(void); virtual ~CMyListBox(void); int AddDetailedString(const LPCTSTR lpszItem, const CString csDetail); ... private: CObArray m_coDetails; };
I have no idea why if I delcared a private array (or vector) variable and then push the elements to it. It always crash! If I use CObArray, I got "privileged instruction" promopt and debugger run at "AfxAssertValidObject". If I use std::vector, I got "Access Violation" and debugger run at "CheckBytes".Code:IMPLEMENT_DYNAMIC(CMyListBox, CDialog) CMyListBox::CMyListBox(void) {} CMyListBox::~CMyListBox(void) {} int CMyListBox::AddDetailedString(const LPCTSTR lpszItem, const CString csDetail) { LPCTSTR lpszDetail = csDetail; m_coDetails.Add((CObject*)lpszDetail); // this line always crash return CListBox::AddString(lpszItem); }
Please could anyone give me some suggestion to solve this problem?
Many thanks!




Reply With Quote