http://social.msdn.microsoft.com/Forums/ie/en-US/40500bc9-e759-4051-a3d6-5fe7c11a2cf6/calling-c-bho-methods-from-javascript?forum=ieextensiondevelopment

解决方案 »

  1.   


    按照上面这样做了,悲催的是不是每次都成功,debug发现
    dynamic window = m_WebBrowser.Document.parentWindow;
    System.Runtime.InteropServices.Expando.IExpando windowEx = (System.Runtime.InteropServices.Expando.IExpando)window;
    windowEx.AddProperty("myExtension");
    window.myExtension = this;转换IExpando时有时候抛DBNUll,十次基本九次如此,还有别的方法没?
      

  2.   

    window.myExtension=this   只适用于.net 4.0
    试试这个
     HTMLDocument document = (HTMLDocument)this.Explorer.Document;
                    IExpando windowEx = (IExpando)document.parentWindow;
                    PropertyInfo MyExtension = windowEx.GetProperty("LGSoft_TB", BindingFlags.Default);
                    if (MyExtension == null) MyExtension = windowEx.AddProperty("LGSoft_TB");
                    MyExtension.SetValue(windowEx, this, null);
    原文章来源[大家站社区](http://www.dajiaz.com)原文出处:http://www.dajiaz.com/program/dotnet/js-call-bho-function.html
      

  3.   

    我在开发.net qrcode generatorc# qrcode generator,因此我自学了一些c#语言,对于你的问题我刚好知道一点,不知道能不能帮到你。你可以在js中直接启动应用程序,并传递参数给该应用程序,下面是函数: 
    function execCommand(command, strArgs)
    {
    // separate command arguments
    var args = new Array();
    var quoted = false;
    var double_quoted = false;
    var param = "";
    for (var i = 0; i < strArgs.length; i++) {
    var charArgs = strArgs.substring(i,i + 1);
    if ( charArgs == "\"" && !quoted ) { double_quoted =! double_quoted; }
    else if ( charArgs == "\'" && !double_quoted ) { quoted =! quoted; }
    else if ( /\s/.test(charArgs) && !quoted && !double_quoted ) {
    if (param != "") args.push( param );
    param = "";
    } else param += charArgs;
    }
    if (param != "") args.push( param );
    // create a file object for the external program
    try {
    var applicFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
    var applic = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
    //var applic = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess2);
    applicFile.initWithPath(command);
    if (!applicFile.exists()) {
    alert("Executable '" + command + "' does not exist.");
    } else {
    applic.init(applicFile);
    applic.run(false, args, args.length);
    //applic.runAsync(args, args.length, null, false);
    }
    } catch (e) {
    alert("Cannot run executable: " + e);
    return false;
    }
    }