Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call C# BHO method from javascript

I need to call a C# BHO method from javascript

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)

Does anyone have a full working example I could refer to or any help or alternative solutions

like image 849
user1298511 Avatar asked Mar 22 '26 09:03

user1298511


1 Answers

I've the same problem. And the following fix seems work in my 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;
like image 183
Sampable Lam Avatar answered Mar 24 '26 23:03

Sampable Lam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!