执行属于其他进程的外部函数

发布于 2024-12-03 12:44:27 字数 460 浏览 0 评论 0原文

我需要帮助解决问题。我有 2 个进程正在运行,一个是看门狗,另一个是简单的测试进程。我需要进程 2 从看门狗调用代码,我这样做的原因是为了减少进程 2 的大小。例如,进程 2 必须从看门狗调用一个名为“IsSafe”的函数。 IsSafe 函数依赖于属于 Watchdog 进程的其他代码,为进程 2 重写此代码是不可行的。我已经想到了一些想法,请您建议哪个是最佳解决方案或提供建议。

想法一

使用命名管道在进程之间进行通信并传递参数和返回值。

想法二

使用共享内存来共享参数和返回值

想法三

使用Windows消息,老实说我认为这行不通

想法四

以某种方式创建一个共享内存的可执行部分并使用远跳转执行此代码。

请您指教。

I would need help with a problem. I have 2 processes running, one the Watchdog and the other a simple test process. I need process 2 to call code from the Watchdog, the reason I do this is to reduce the size of process 2. For example process 2 must call a function called "IsSafe" from the watchdog. The IsSafe function relies on other code belonging to Watchdog process and it will not be viable to rewrite this code for process 2. I have thought of ideas, please could you advise on which is the best solution and or give advice.

Idea One

Use Named pipes to communicate between processes and pass parameters and return values around.

Idea Two

Use Share Memory to share parameters and return values

Idea Three

Use windows messages, I honestly think this will not work

Idea Four

Somehow create a executable portion of shared memory and execute this code with a far jmp.

Please could you advise.

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

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

发布评论

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

评论(4

梦里的微风 2024-12-10 12:44:27

RPC 很早以前就被发明了。然后是 COM 之上。我认为最好忘记你的想法,但如果必须的话,请使用 COM。

顺便说一句,要在同一台 Windows 计算机上的进程之间进行通信(无需 COM),请使用邮槽。

看来您忘记了它们在您的列表中。

干杯&呵呵,,

RPC was invented long ago. Then COM on top of that. In my opinion best forget your idea, but if you must, use COM.

By the way, to communicate between processes on the same Windows machine without COM, use mailslots.

Seems you forgot about them in you list.

Cheers & hth.,

怀念你的温柔 2024-12-10 12:44:27

尽管将代码放入需要调用它的进程中通常是一个好建议,但在看门狗(还有调试器和任何其他形式的错误处理程序)的特殊情况下,使用单独的进程是正确的。您不希望看门狗由于主代码中的错误而失败,因此它需要是一个单独的进程。

在这种情况下,命名管道是理想的选择, TransactNamedPipe 函数 就是为此而设计的。

Although putting the code in the process which needs to call it is good advice in general, in the particular case of a watchdog (also debugger and any other form of error handler) using separate processes is correct. You don't want the watchdog to fail due to an error in the main code, so it needs to be a separate process.

A named pipe would be ideal in this scenario, the TransactNamedPipe function is designed just for this.

纸短情长 2024-12-10 12:44:27

DLL 是想法 4 的标准实现。它被加载到两个地址空间中,但在物理 RAM 中共享。你不需要特殊的技巧;它适用于任何地方,Windows 将为您处理任何安全问题。

它也可以移植到大多数其他操作系统,尽管它们通常被称为其他名称,例如 Linux 上的 .so。

A DLL is the standard implementation of idea 4. It's loaded in both address spaces, but shared in physical RAM. You don't need special tricks; it works everywhere and Windows will deal with any security issues for you.

It's also portable to most other Operating Systems, although they're generally called something else, e.g. .so on Linux.

热鲨 2024-12-10 12:44:27

您真正需要的只是一些 IPC。对于轻量级且简单的解决方案,只需使用 WM_APP 定义应用程序特定消息并从 wParam/lParam 获取参数的映射即可。如果您发现需要超过 8 个字节,可以使用 WM_COPYDATA 代替。

All you really need is some IPC. For a lightweight and easy solution, simply define an application specific message with WM_APP and have a mapping from the wParam/lParam for parameters. If you find you need more than 8 bytes, you could use WM_COPYDATA instead.

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