我正在尝试在 mfc 应用程序和 wpf 应用程序之间建立双向通信。我正在从这两篇文章中获得帮助: Interprocess Communication Between .NET and MFC Using WM_COPYDATA和 Interprocess 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/