简体   繁体   English

从javascript调用C#BHO方法

[英]Call C# BHO method from javascript

I need to call a C# BHO method from javascript 我需要从javascript调用C#BHO方法

I have followed the solution given in this question 我已经按照这个问题给出的解决方案了

I get the error: 我收到错误:

'mshtml.HTMLWindow2Class' does not contain a definition for 'myExtension'.

I cannot assign: 我不能指定:

dynamic window = browser.Document.parentWindow; 

as parentWindow is undefined, I have to cast to (mshtml.IHTMLDocument2) and (mshtml.IHTMLWindow2) 由于parentWindow未定义,我必须转换为(mshtml.IHTMLDocument2)和(mshtml.IHTMLWindow2)

Does anyone have a full working example I could refer to or any help or alternative solutions 有没有人有一个我可以参考的完整工作示例或任何帮助或替代解决方案

I've the same problem. 我有同样的问题。 And the following fix seems work in my BHO: 以下修复似乎在我的BHO中起作用:

dynamic window = _webBrowser.Document.parentWindow;
var windowEx = (IExpando)window;
PropertyInfo p = windowEx.AddProperty("myExtension");
p.SetValue(windowEx, this);

instead of: 代替:

dynamic window = _webBrowser.Document.parentWindow;
var windowEx = (IExpando)window;
PropertyInfo p = windowEx.AddProperty("myExtension");
window.myExtension = this;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM