Need help getting custom IOleClientSite object's IDispatch::Invoke to execute when using WebBrowser

B

BG

I have no problem getting this code to run the invoke method of idispatch
only using MSHTML and C# for .net framework 1.1.

class Class1: IOleClientSite
{
public Class1()
{
IOleObject doc = (IOleObject) new mshtml.HTMLDocument();
doc.SetClientSite(this);
}

[DispId(-5512)]
public int IDispatch_Invoke()
{
return DLCTL_NO_SCRIPTS | DLCTL_NO_JAVA |
DLCTL_NO_DLACTIVEXCTLS | DLCTL_NO_RUNACTIVEXCTLS |
DLCTL_SILENT | DLCTL_DLIMAGES | 0;
}
}

But I do not want to completely rewrite the webbrowser object's container
and all those methods and events just to be able to tell mshtml not to run
java and activex and scripts when it surfs to a web page. So I try code like
this:

class Form1 : Form, IOleClientSite
{
AxWebBrowser browser;

public Form1()
{
object n = null;

browser = new AxWebBrowser();
this.Controls.Add(browser);
browser.Navigate("about:blank", ref n, ref n, ref n, ref n);
((IOleObject) browser.Document).SetClientSite(this);
}

[DispId(-5512)]
public int IDispatch_Invoke()
{
return DLCTL_NO_SCRIPTS | DLCTL_NO_JAVA |
DLCTL_NO_DLACTIVEXCTLS | DLCTL_NO_RUNACTIVEXCTLS |
DLCTL_SILENT | DLCTL_DLIMAGES | 0;
}
}

But it doesnt call my invoke method. So then I figure that it may have
already set the client site, within webbrowser when i called Navigate, so I
slightly alter the above code from:

browser.Navigate("about:blank", ref n, ref n, ref n, ref n);
((IOleObject) browser.Document).SetClientSite(this);

to:

browser.Navigate("about:blank", ref n, ref n, ref n, ref n);
((IOleObject) browser.Document).SetClientSite(null);
((IOleObject) browser.Document).SetClientSite(this);

This code gets my invoke method called but about 1 second after this,
everything totally bombs with a nullreferenceexception.

So my question is, does anyone know how I can get my IDispatch::Invoke
method called when using the WebBrowser object? Or to put it another way,
how can I tell the WebBrowser to not run activex, java, scripts and whatever
else it's got that isn't straight html without totally rewriting the
webbrowser object on my end?

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top