在 FireBreath 框架中使用 Win32 API CreateProcess

发布于 2025-01-03 08:41:36 字数 450 浏览 1 评论 0原文

我正在尝试使用 Firebreath 框架开发一个浏览器插件。我想要实现的第一件事是让插件能够进行traceroute。目前我是在Windows7上做的。目前我选择使用Win32API CreateProcess来调用命令shell。通过设置 dwFlags = STARTF_USESHOWWINDOW ,我可以在执行期间隐藏命令 shell 窗口。

问题: createProcess 是在一个名为 run() 的方法中实现的,我使用 JS 调用它进行测试。当我调用plugin().run()时,traceroute运行良好,并且输出已按照我的要求成功写入文本文件中。然而在执行过程中,浏览器变得无响应,最后插件在跟踪路由完成几秒钟后崩溃。由于我是插件开发的新手,对c++只有一点了解,我想知道为什么会出现这个问题。仅供参考,如果我没有隐藏 commandshell 窗口,该插件会产生奇迹 - 执行跟踪路由时浏览器会做出响应。

I'm trying to develop a browser plugin using Firebreath framework. The first thing I would like to achieve is to make the plugin able to do traceroute. For now I'm doing it on Windows7. Currently I chose to use Win32API CreateProcess to call the command shell. By setting dwFlags = STARTF_USESHOWWINDOW , I'm able to hide the command shell window during execution.

PROBLEM : The createProcess is implemented in a method called run() where I called it using JS for testing. When I called plugin().run(), the traceroute is working well, and the output was succesfully written in a textfile as I wanted. However during the execution, the browser become unresponsive and lastly the plugin crashed seconds after the traceroute completed. As I am new to plugin development and only have a little knowledge on c++ , I wonder why this problem arisen. FYI, if I did not hide the commandshell window, the plugin worked wonder - the browser was responsive while the traceroute was executed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追星践月 2025-01-10 08:41:36

在任何 NPAPI 插件(使用 FireBreath 或其他)中,不要阻塞主(javascript)线程,这一点非常重要。您想要做的事情可以通过多种方式完成;我可能会传入一个回调,启动一个新线程,在那里执行 createprocess,然后在完成结果时触发 js 回调。

请参阅 FireBreath 提示:异步 Javascript 调用

需要注意的一件事是,如果插件在调用期间关闭,您需要能够终止线程(和进程)。

It is very important in any NPAPI plugin (with FireBreath or otherwise) that you don't block the main (the javascript) thread. What you're trying to do could be done in a couple of ways; I'd probably pass in a callback, start a new thread, do the createprocess there, and then fire the js callback when it completes with the result.

See FireBreath Tips: Asynchronous Javascript Calls.

The one thing to watch out for is you need to be able to terminate the thread (and the process) if the plugin is shut down during the call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文