Print Page | Close Window

Access Violation with CXTPControlComboBox

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=8859
Printed Date: 03 July 2024 at 3:55am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Access Violation with CXTPControlComboBox
Posted By: Anna2004
Subject: Access Violation with CXTPControlComboBox
Date 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



Replies:
Posted By: jimmy
Date 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



Posted By: Anna2004
Date 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?



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net