本文介绍了如何从的ActiveX调用java脚本函数或C#dll的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Active-X级用C#这是多线程的。我需要从我的ActiveX调用JavaScript。我通过Microsoft.mshtml尝试过。

I have active-x class written in c# which is multi-threaded. I need to call javascript from my activeX. I tried it by Microsoft.mshtml .

/*JS

function do_Print() {
    control.setPage(this);
    control.scriptPrint();
}

function report_back(report){
    alert("Report:"+report);
}


C#

    public void setPage(mshtml.HTMLWindow2Class JSFile) {
                window = JSFile;
    }
    public void scriptPrint(){
                window.execScript("report_back('Printing complete!')", "JScript");
    }
    */



但其引发异常

But its throwing exception

无法投型
'mshtml.HTMLWindow2Class'的COM对象的接口
型'mshtml.DispHTMLWindow2'。

有圆的另一种方式。我能够从Java调用脚本的Active-X功能,但反之亦然还是得到了上面的异常。任何想法多线程C#的Active-X调用javascript函数???

Is there another way round. I am able to call active-x function from java script but vice versa still got above exception. Any idea for multi-threaded c# active-x calling javascript function ???

推荐答案

您可以像这样访问HTML

you can access html like this

private void MyControl_Load(object sender, EventArgs e)
        {
            if (this.Site != null)
            {
                htmldoc = (HtmlDocument)this.Site.GetService(typeof(HtmlDocument));

            }


        }

然后在任意按钮点击我们的C#控制invoke方法点击HTML按钮

then on any button click on our C# control invoke method to click html button

 HtmlElement setCLIButton = htmldoc.GetElementById("searchButton");
                setCLIButton.InvokeMember("onClick");



通过这样的方式,你可以叫你javacsript功能,希望它会帮助别人。

by this way you can call your javacsript function hope it will help someone.

这篇关于如何从的ActiveX调用java脚本函数或C#dll的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 20:22