none
Is it possible to cast COM object to the custom interface? RRS feed

  • Question

  • I have following code which succesfully works using some COM wrapper library with all needed managed types for COM objects

    mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)_webBrowser.Document;
    
    mshtml.HTMLIFrameClass iframe = (doc).getElementById("SomeFrameName") as mshtml.HTMLIFrameClass;
    
    if (string.Equals(iframe.readyState.ToString(), "complete", StringComparison.OrdinalIgnoreCase))
    
    {
    
     // Do something
    
    }
    
    
    But I need to avoid this COM wrapper Micrososft.mshtml.dll and use custom interfaces for this reason, so please explain me how way can I work with COM objects with custom interfaces? How do I write them and avoid classes mshtml.HTMLDocumentClass and mshtml.HTMLIFrameClass?
    Friday, September 24, 2010 11:25 PM

Answers

  • To get you started, you will need to go through the DomElement property to get at the COM object.  I haven't thought through all the details, but wanted to let you know this much so you can head down the right track.

    doc.getElementById("SomeFrameName").DomElement

    > But I need to avoid this COM wrapper Micrososft.mshtml.dll

    Not sure why.  It will be loaded into your process anyways because it is a core part of Internet Explorer and you are using the Internet Explorer control.

    EDIT:  If you do not want to add the reference to MSHTML, you can supposedly use reflection on the DomElement.  Mentioned on this page: http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.domelement.aspx

     

    • Marked as answer by SamAgain Tuesday, October 5, 2010 6:53 AM
    Saturday, September 25, 2010 12:17 AM