gpt4 book ai didi

c++ - MFC与WPF进程间通信

转载 作者:太空宇宙 更新时间:2023-11-04 13:12:41 24 4
gpt4 key购买 nike

我正在尝试在 mfc 应用程序和 wpf 应用程序之间建立双向通信。我正在从这两篇文章中获得帮助: Interprocess Communication Between .NET and MFC Using WM_COPYDATAInterprocess Communication Between .NET and MFC Using C# and COPYDATA

到目前为止,我已经设法将消息从 wpf 发送到 mfc。但现在我希望 mfc 应用程序将消息发送到 wpf 应用程序。我需要做什么才能实现这一目标?

在 mfc 端,我将句柄存储为

storedHandle = (HWND)intPtr;

然后使用此句柄通过以下行发送消息:

::SendMessage(pFrame->storedHandle, WM_COPYDATA, 0, 0);

但是 wpf 没有收到消息。

最佳答案

与其使用传统的基于窗口的通信,不如考虑使用更现代的机制,例如 Windows Mailslots:

对于 C#,这里有一个包装器: http://www.codeproject.com/Articles/623268/Csharp-wrapper-for-Mailslots

也可以使用 \\.\mailslot 通过文件系统访问消息:

https://blog.didierstevens.com/2006/07/13/do-you-have-mailslots-on-your-windows-pc/

关于c++ - MFC与WPF进程间通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38997513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com