如何在 Windows 服务和进程之间使用命名互斥锁和共享内存? [英] How to use named mutex and shared memory between a windows service and a process?

查看:47
本文介绍了如何在 Windows 服务和进程之间使用命名互斥锁和共享内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C++\MFC 编写的代码,它作为 Windows 服务和(普通)C++\MFC Windows 进程运行 - 现在我希望使用命名互斥和共享内存(文件映射)在两者之间进行通信.

I'm have a code written in C++\MFC that is run as a Windows Service and a (normal) C++\MFC Windows process - now I wish to communicate between the two using named Mutex and Shared memory (File mapping).

这怎么可能?

推荐答案

这取决于您的沟通需求.通常,服务创建互斥锁和共享内存,客户端打开它们并执行操作.OutputDebugString() 是使用互斥锁和共享内存(以及一些事件)的 IPC 的经典示例.这里详细介绍了 OutputDebugString() 的工作原理;你可以做类似的事情.

It depends on your communication requirements. Generally the service creates the mutex and shared memory and the clients open them and do stuff. OutputDebugString() is a classic example of IPC using a mutex and shared memory (and some events). Here is a detailed examination of how OutputDebugString() works; you could do something similar.

这篇关于如何在 Windows 服务和进程之间使用命名互斥锁和共享内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆