How to get a IHTMLElement pointer to the <object> tag hosting an activex control

前端 未结 2 952
情书的邮戳
情书的邮戳 2021-01-13 22:10

I have an ActiveX control generated by the FireBreath framework (http://firebreath.org). I need to get a reference to the tag in the page that hosts the plug
相关标签:
2条回答
  • 2021-01-13 22:32

    Thanks to FireBreath contributor jtojanen from Finland, we finally have a solution.

    The first thing is that the COM object must be registered as "Apartment", not "Single" (in the registry). Otherwise, this will not work; seems to be a bug in COM.

    Then anywhere after SetClientSite is called, you can do the following:

    CComQIPtr<IOleControlSite> site(m_spClientSite);
    CComPtr<IDispatch> dispatch;
    site->GetExtendedControl(&dispatch);
    CComQIPtr<IHTMLElement2> htmlElement = dispatch;
    

    Hope this saves someone some time; it's taken me almost 2 years to find someone who could answer this for me.

    The object in htmlElement will be the <object> tag that wraps your plugin; so if you queryInterface for any of your interfaces, it should succeed, but it may not actually literally be your object, it will likely be a wrapper to your object.

    0 讨论(0)
  • 2021-01-13 22:39

    In C#:

        public int SetSite(object site)
        {
            if (site != null)
            {
                var oleControl = (IOleControlSite)site;
                object oHtmlElement;
                oleControl.GetExtendedControl(out oHtmlElement);
                var htmlElement = (IHTMLElement2)oHtmlElement;
                ...
            }
        }
    
    0 讨论(0)
提交回复
热议问题