Windows 服务通信选项

发布于 2024-12-09 01:29:17 字数 294 浏览 1 评论 0原文

我正在开发一项服务,该服务将作为系统运行,并将在后台处理长时间运行的任务。我现在需要以任务托盘图标的形式向用户显示一些反馈,我还希望能够从任务托盘图标暂停/恢复任务,因此我的要求是向任一方向发送消息并接收任意消息返回响应的长度数据块。单个请求/响应就可以了,但它需要双向工作。

这是在 Windows 中使用 C++(非 MFC)。

我研究过 MIDL/RPC,因为我过去使用过它,但我需要首先定义一个严格的接口规范,并且不能返回任意长度的数据(据我所知)。

对于我可以用于此目的的库有什么建议吗?

谢谢, J

I'm developing a service which will run as System and will process long-running tasks in the background. I now need to display some feedback to the user in the form of a tasktray icon and I would also like to be able to pause/resume the tasks from the tasktray icon so my requirement is to send a message in either direction and receive an arbitrary length data block back in response. A single request/response would be fine but it needs to work in both directions.

This is using C++ (non-MFC) in Windows.

I've looked at MIDL/RPC as I've used it in the past but I need to define a rigid interface spec first and cannot return arbitrary length data (as far as I am aware).

Are there any suggestions for a library I could use for this?

Thanks,
J

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

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

发布评论

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

评论(2

翻身的咸鱼 2024-12-16 01:29:17

COM是Windows中RPC的最佳解决方案。它非常强大并且易于编写。 Raw MS-RPC 也不错。使用两者都可以返回任意长度的数据,请参阅 size_is MIDL 属性:

HRESULT Proc7(
     [out] long  * pSize,
     [out, size_is( , *pSize)] my_type ** ppMyType); /* Specifies a pointer 
                                              to a sized pointer, 
                                              which points to a block 
                                              of my_types, whose size is
                                              unknown when the stub 
                                              calls the server. */

COM is the best solution for RPC in windows. It is very powerful and easy to write. Raw MS-RPC is good too. With both you can return arbitrary length data, see size_is MIDL attribute:

HRESULT Proc7(
     [out] long  * pSize,
     [out, size_is( , *pSize)] my_type ** ppMyType); /* Specifies a pointer 
                                              to a sized pointer, 
                                              which points to a block 
                                              of my_types, whose size is
                                              unknown when the stub 
                                              calls the server. */
左秋 2024-12-16 01:29:17

您可以使用以下任何一种:

  • TCP/IP
  • UDP
  • 管道
  • 共享内存(即内存映射文件)

编辑 - 根据评论:

一些基于共享内存的解决方案,包括源代码:

You can use any of the following:

  • TCP/IP
  • UDP
  • Pipe
  • shared memory (i.e. memory-mapped file)

EDIT - as per comment:

Some shared memory based solutions including source code:

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