locked
Advanced COM-Interop for mshtml in .NET 2.0 Beta RRS feed

  • Question

  • Hello,

    I'm trying to use mshtml as a robust ui-less html->dom parser (like in Microsoft's walkall example).

    I'm trying to do it using C# and VS2005 beta, with the .NET Framework 2.0.

    The problem I'm having is in telling mshtml not to run any active content and not to download images.

    I've tried to define a IDispatch invoke handler, but it is bever being called!

    My code is attached bellow (comsupport is a file I found on the web which has the definiotns for all the COM interfaces. It's not posted here because it is VERY long.).

    Thanks,
    Offir
    ------ WindowsApplication1.cs --------------- 

    using System; 
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using mshtml;
    using System.Runtime.InteropServices;


    namespace WindowsApplication1 {
       public partial class Form1 : Form
       {
          public Form1()
          {
             InitializeComponent();
          }
          private void Form1_Load(object sender, EventArgs e)
          {
             IHTMLDocument2 doc = new HTMLDocumentClass();
             IOleObject obj = doc as IOleObject;
             obj.SetClientSite(new DownloadOnlySiteNoScript());
          }
       }



       public class DownloadOnlySiteNoScript : IOleClientSite
       {
          public DownloadOnlySiteNoScript()
          {
             MessageBox.Show("Created");
          }

          
          [DispId(-5512)]
          public int Idispatch_Invoke_Handler()
          {
             MessageBox.Show("This one should be called but it isn't.");
             return
                 (int) ComSupport.DLCTL_NO_SCRIPTS |
                 (int) ComSupport.DLCTL_NO_JAVA |
                 (int) ComSupport.DLCTL_NO_DLACTIVEXCTLS |
                 (int) ComSupport.DLCTL_NO_RUNACTIVEXCTLS |
                 (int) ComSupport.DLCTL_DOWNLOADONLY |
                 (int) ComSupport.DLCTL_SILENT |
                 (int) ComSupport.DLCTL_URL_ENCODING_ENABLE_UTF8 |
                 0;
           }

       
           // IOleClientSite
            public int SaveObject() { return HRESULT.S_OK; }


             public int GetMoniker(uint dwAssign, uint dwWhichMoniker, out Object ppmk)
             {
                 ppmk = null; return HRESULT.E_NOTIMPL;
             }
             public int GetContainer(out IOleContainer ppContainer)
           {
                ppContainer = null; return HRESULT.E_NOINTERFACE;
             }
             public int ShowObject()
             {
                return HRESULT.S_OK;
             }
             public int OnShowWindow(int fShow)
            {
                return HRESULT.S_OK;
             }
             public int RequestNewObjectLayout() { return HRESULT.S_OK; }
        }
    }


     

    Tuesday, August 2, 2005 2:36 PM

Answers

All replies

  • Hello Offir,

    I haven't tried your code snippet, but if you are still having this issue, I would suggest debugging with CLRSpy (Customer Debug Probes) to verify the marshalling is correct. You can find more info on CLRSpy on Adam Nathan's Managed/Native Interop blog.

    Hope that helps, and please feel free to post back to the forum with more technical details, or if you find a solution to your problem!

    Thanks,
    Stephen
    http://blogs.msdn.com/stfisher
    Monday, September 12, 2005 10:01 PM
  • Please make your object (form) comvisible. You are all set !

    [ComVisible(true)]
    public partial class Form1 : Form 
    {
    }

    Sunday, December 11, 2005 4:01 PM
  • 'm actually using Offir's code, but I'm having one problem... how do you load a stream (or file or whatever that is not a url, but rather a local resource) into the HTMLDocument ?
    Thursday, June 15, 2006 12:15 AM