Calling C# BHO methods from Javascript In Internet Explorer 10 (Release preview)
Asked Answered
M

1

7

I'm trying to develop a BHO for the release preview of IE 10. The BHO needs to be able to allow javascript to call a C# function.

I've followed the instructions available here:

Calling C# BHO methods from Javascript

These instructions work great in IE 9.

Unfortunately, I've found that they only work for the first tab created in IE 10. The second and subsequent tabs do not expose the BHO interface to Javascript. On occasion, new tabs work, but most of the time they do not. Moreover, it fails silently. I'm guessing this has something to do with the process model -- but again, it works fine in IE 9 (which has the same process model).

Here is the specific snippet of code that I'm using:

private void InstallJSObject(IHTMLWindow2 window)
{
    // Install our javascript object
    IExpando windowEx = (IExpando)window;

    PropertyInfo property = windowEx.GetProperty("myBHO", System.Reflection.BindingFlags.IgnoreCase);
    if (property == null)
    {
        property = windowEx.AddProperty("myBHO");
    }
    property.SetValue(windowEx, this, null);
}

Before posting, I researched the following: http://bit.ly/R9qldf

Midsummer answered 13/8, 2012 at 16:0 Comment(3)
You might want to post this on Microsoft Connect as it seems more like a bug for the release candidate (which is still pre-release software) rather than something that's been backed for release. This could very well be "too localized".Viridescent
I'm seeing the same problem with the released version of IE10. This problem still exists.Enscroll
Well how are you calling InstallObject? If you're following this article: codeproject.com/Articles/19971/… How many times are you getting SetSite called? It should be called once per browser. Also, remember, each tab is a different process so if you're just using the debugger to verify then you'll have to attach to each process.Airminded
E
0
var myATL = new ActiveXObject("MySampleATL.MyClass");

if (myATL.IsBHOInstalled)
       alert (myATL. SayHelloFromBHO());

else
       alert ("BHO isn't installed now !");

window.external.AddFavorite(<url>, "text");

Extracted from here.

The the blog is dated back to April'07, still, may be this is what you were looking for..

Excurvature answered 31/7, 2014 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.