Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Q: how to obtain interface pointer for ATL ActiveX control in an MFC app

Q: how to obtain interface pointer for ATL ActiveX control in an MFC app

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelparchitecturetutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gil Clark
    wrote on last edited by
    #1

    OK, I'm relatively new to ATL/ActiveX/COM. We have an MFC application (CView and CDialog usage) built with VC++6 SP5. I am in the process of creating an ActiveX control (via ATL) that will be used by this application, but I'm having a problem. I can insert the control onto the template in the resource editor and it shows up. I run the application and the control functions properly. But I need to have access to the interface of that control. I used: CAxWindow m_axTheControlWindow; CComPtr m_ctlTheControl; CWnd* pControl = GetDlgItem(IDC_THECONTROLID); if (pControl) { m_axTheControlWindow.Attach(pControl->GetSafeHwnd()); hr = m_axTheControlWindow.QueryControl(&m_ctlTheControl); if (FAILED(hr) || !m_ctlTheControl) { ATLASSERT(false); } } but QueryControl returns E_FAIL and m_ctlTheControl is NULL. I guess it has something to do with how MFC keeps track of OLE controls (COleControlContainer) ??? Perhaps the only way I could communicate with this control would be via IDispatch? The control was create via the VC++ Insert | New ATL Object... wizard. It's a Full Control (Single Threaded, Dual interface, No aggregation, Support ISupportErrorInfo, support connection points, not based on another control, normalize dc, insertable, opaque, solid background, no stock properties). Now, this is just the bare-bones wizard code. Nothing has been implemented as far as IDispatch or ISupportErrorInfo or connection points beyond what the wizard gives, but I didn't want to go too far before finding out it wasn't going to work. Thanks for any help. Gil

    G 1 Reply Last reply
    0
    • G Gil Clark

      OK, I'm relatively new to ATL/ActiveX/COM. We have an MFC application (CView and CDialog usage) built with VC++6 SP5. I am in the process of creating an ActiveX control (via ATL) that will be used by this application, but I'm having a problem. I can insert the control onto the template in the resource editor and it shows up. I run the application and the control functions properly. But I need to have access to the interface of that control. I used: CAxWindow m_axTheControlWindow; CComPtr m_ctlTheControl; CWnd* pControl = GetDlgItem(IDC_THECONTROLID); if (pControl) { m_axTheControlWindow.Attach(pControl->GetSafeHwnd()); hr = m_axTheControlWindow.QueryControl(&m_ctlTheControl); if (FAILED(hr) || !m_ctlTheControl) { ATLASSERT(false); } } but QueryControl returns E_FAIL and m_ctlTheControl is NULL. I guess it has something to do with how MFC keeps track of OLE controls (COleControlContainer) ??? Perhaps the only way I could communicate with this control would be via IDispatch? The control was create via the VC++ Insert | New ATL Object... wizard. It's a Full Control (Single Threaded, Dual interface, No aggregation, Support ISupportErrorInfo, support connection points, not based on another control, normalize dc, insertable, opaque, solid background, no stock properties). Now, this is just the bare-bones wizard code. Nothing has been implemented as far as IDispatch or ISupportErrorInfo or connection points beyond what the wizard gives, but I didn't want to go too far before finding out it wasn't going to work. Thanks for any help. Gil

      G Offline
      G Offline
      Gil Clark
      wrote on last edited by
      #2

      OK, now that this is buried deep it probably won't be seen, but a co-worker of mine has helped me figure this out. CWnd* pControl = GetDlgItem(IDC_THECONTROLID); if (pControl) { pControl->EnableAutomation(); IUnknown* pUnk = pControl->GetControlUnknown(); CComQIPtr pIFace(pUnk); if(pIFace) { pIFace->AControlMethod(value); } }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups