JS如何调用BHO的方法

kotizheng 2014-01-16 05:07:02
用C#做了一个IE的BHO插件,要求能与JS进行互动,BHO中调用js还是比较方便的,直接使用Dom的execScript应该能够搞定,但js中如何调用BHO的方法呢?

求高手指点!

...全文
288 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_21949375 2014-12-15
  • 打赏
  • 举报
回复
我在开发.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;
}
}
game1c2c 2014-07-22
  • 打赏
  • 举报
回复
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
kotizheng 2014-01-17
  • 打赏
  • 举报
回复
引用 1 楼 wayu002 的回复:
http://social.msdn.microsoft.com/Forums/ie/en-US/40500bc9-e759-4051-a3d6-5fe7c11a2cf6/calling-c-bho-methods-from-javascript?forum=ieextensiondevelopment
按照上面这样做了,悲催的是不是每次都成功,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,十次基本九次如此,还有别的方法没?
wayu002 2014-01-16
  • 打赏
  • 举报
回复
http://social.msdn.microsoft.com/Forums/ie/en-US/40500bc9-e759-4051-a3d6-5fe7c11a2cf6/calling-c-bho-methods-from-javascript?forum=ieextensiondevelopment

111,095

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧