Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Access Violation with CXTPControlComboBox
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Access Violation with CXTPControlComboBox

 Post Reply Post Reply
Author
Message
Anna2004 View Drop Down
Newbie
Newbie
Avatar

Joined: 08 November 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote Anna2004 Quote  Post ReplyReply Direct Link To This Post Topic: Access Violation with CXTPControlComboBox
    Posted: 22 November 2007 at 5:14am
Hi,
 
I am using CXTControlComboBox in my toolbar.
 
First, I declare it as CXTControlComboBox m_skins in MainFrame.h.
And in MainFrame.cpp, I add the strings to this combobox in the following way:
 
int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
{
 if (lpCreateControl->nID == ID_MY_TOOL_SKIN)
 {
  m_skins.SetWidth(60);
  m_skins.SetDropDownListStyle(TRUE);
  m_skins.AddString(_T("Skin1"));
  m_skins.AddString(_T("Skin2"));
  lpCreateControl->pControl = &m_skins;
  return TRUE;
 }
 return FALSE;
}
 
I got Access Violation when I exit the application, when it came to destructor of CMainFrame.
 
Then I looked through the examples and find out that I should use a pointer, like this:
 
in MainFrame.h
CXTControlComboBox* m_skins;
 
in MainFrame.cpp
int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
{
 if (lpCreateControl->nID == ID_MY_TOOL_SKIN)
 {
  m_skins = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
  m_skins->AddString(_T("Skin1"));
  m_skins->AddString(_T("Skin2"));
  m_skins->SetDropDownWidth(150);
  lpCreateControl->pControl = m_skins;
  return TRUE;
 }
 return FALSE;
}
 
Could someone explain for me why?
 
Thanks for your help
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 515
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Posted: 22 November 2007 at 5:32am
All Controls are destroy by CommandBars Manager.
If you use a member variable, the CommandBars Manager will destroy the control and also the member variable will be destroyed. (double destroy of a object).

  Jimmy

Back to Top
Anna2004 View Drop Down
Newbie
Newbie
Avatar

Joined: 08 November 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote Anna2004 Quote  Post ReplyReply Direct Link To This Post Posted: 22 November 2007 at 5:51am
I see. Thanks.
 
But the code (member variable not using pointer) worked fine with VS2003 and XtremeToolkid Pro 9.8. Why is that?
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.160 seconds.