Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

createcontrol() inside an activeX control

Status
Not open for further replies.

gorgor

Programmer
Aug 15, 2002
164
US
In MFC, MSVC++ 6.0, I have an activeX control that contains a window of a class (CMyFormView) derived from CFormView. Inside that window I am trying to use CWnd::CreateControl() to load another activeX control inside the "container" activeX control. The CLSID of the activeX control i'm trying to load is in the string "pData".

In my CMyFormView class of the "container" activeX control, I have the code in the OnDrop message handler:
m_control.CreateControl(pData, NULL, 0, m_rHotRect, this, 110001, NULL, FALSE, NULL);

m_control is a CWnd object.

Everything builds fine, but when I run the app, I get a runtime crash...
"Unhandled exception at 0x5f47c2cc (MFC42D.DLL) in containerapp.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1."
Containerapp.exe is the MFC container application that I created to host the controls. That's all the information I have and I know it's crashing at the CreateControl function. Has anything seen anything like this before? Are there any gotcha's that I should know about when loading activeX controls inside other activeX controls?

Thanks in advance.
 
Sorry, this is what happens during Debug:

ERROR: "Unhandled exception at 0x5f50f51d (MFCO42D.DLL) in containerapp.exe: 0xC0000005: Access violation reading location 0x00000000."

It breaks at the following function in some file called occcont.cpp:
BOOL CWnd::InitControlContainer()
{
if (m_pCtrlCont == NULL)
{
BOOL bSuccess;

bSuccess = CreateControlContainer( &m_pCtrlCont );
if (bSuccess && (m_pCtrlCont == NULL))
{
BREAKS HERE!---> // The window wants to use the default control container.
TRY
{
m_pCtrlCont = afxOccManager->CreateContainer(this);
}
END_TRY
}
}

Any ideas??
 
Did you find a solution to this problem?

I am doing basically the same thing, but with a MSFlexGrid and getting the same error as you are:

dervMSFlexGrid m_MyGrid; //In Header

m_MyGrid.Create(NULL, "Grid", WS_VISIBLE | SBS_HORZ | BS_FLAT, CRect(0,0,400,300), this, IDC_GRID_MAIN); //In OnCreate(...)
 
Soon after I submitted the previous post (reply), I found the solution:

// CContainerApp initialization (In the case for ActiveX control, use your COleControlModule derived class)
BOOL CContainerApp::InitInstance()
{
AfxEnableControlContainer();//Enables Controls 2 contain Other Controls
...
}

Add the following to your project’s STDAFX.H header file:
#include <Afxdisp.h>

Hope that works for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top