ActiveX/COM Problem

I'm creating a chartfx component in a in proc com server:
      m_Chart.Create("ChartFx", WS_VISIBLE | WS_CHILD | WS_BORDER, aRect, this, IDR_CHART1);
      m_Chart.SetWindowPos(0, 0, 0, aRect.Width(), aRect.Height(), SWP_NOMOVE | SWP_NOZORDER);

when I close the app, here's the call stack:
NTDLL! 77f76148()
NTDLL! 77f8a8b9()
NTDLL! 77f83209()
KERNEL32! 77f11ad0()
CFX32! 0277c496()
USER32! 77e71ab7()
USER32! 77e71a77()
NTDLL! 77f7624f()
CFX32! 02771c05()
COleDispatchDriver::~COleDispatchDriver() line 80 + 15 bytes
COleControlSite::~COleControlSite() line 99 + 33 bytes
COleControlSite::`scalar deleting destructor'(unsigned int 1) + 15 bytes
COleControlContainer::~COleControlContainer() line 120 + 31 bytes
COleControlContainer::`scalar deleting destructor'(unsigned int 1) + 15 bytes
CWnd::OnDestroy() line 764 + 34 bytes
CWnd::OnWndMsg(unsigned int 2, unsigned int 0, long 0, long * 0x0012f678) line 1815
CWnd::WindowProc(unsigned int 2, unsigned int 0, long 0) line 1575 + 30 bytes

When I QueryInterface I do a Release so the reference count should be 1.

I'm doing the same with formula1 and have no problems.  

Anyone know why the ReleaseDispatch() is being called before any of the destructor methods?
Who is Participating?
Tommy HuiConnect With a Mentor EngineerCommented:
I think there's a problem in this code:

  m_pVolSurf = GetETSControl(lpUnk, &lpContext);

You are calling GetETSControl() to retrieve the IID_IMarketSet_SnapIn interface. However, as soon as the GetETSControl function returns, you are release the interface that was returned. The code should be

  m_pVolSurf = GetETSControl(lpUnk, &lpContext);
  lpUnk->Release();  // << new stuff here
  lpUnk = NULL; // << new stuff here

I think this is what you want.

Tommy HuiEngineerCommented:
When you do a QueryInterface(), which interface do you release?
richpAuthor Commented:
     m_pVolSurf = GetETSControl(lpUnk, &lpContext);
VolSurface * CVolatilityCtl::GetETSControl(      IUnknown* pUnk, ISnapInMarketSet** ppETSCtrl)
      if (!pUnk || pUnk->QueryInterface(IID_IMarketSet_SnapIn, (LPVOID*) ppETSCtrl) != S_OK)
            return NULL;

All Courses

From novice to tech pro — start learning today.