[英]Is Memory-mapped-files as ipc between uwp app and win32 process supported
The official docs doesn't properly state if ipc via memory-mapped-files is supported in uwp. I was working on a scenario for ipc between an uwp app and its desktop extension.如果 uwp 支持通过内存映射文件的 ipc,官方文档不正确 state。我正在研究 uwp 应用程序及其桌面扩展之间的 ipc 场景。 While I can create memory-mapped-files using
System.IO.MemoryMappedFiles
from uwp app with codeGeneration
capability but opening from win32 process fails with message Unable to find the specified file.
虽然我可以使用具有
codeGeneration
System.IO.MemoryMappedFiles
内存映射文件,但从 win32 进程打开失败并显示消息Unable to find the specified file.
. . Is ipc via memory-mapped-files supported in uwp, if yes, what is the proper way to do it??
uwp 是否支持通过内存映射文件的 ipc,如果是,正确的方法是什么?
Minimal reproduceable sample. 最小可重现样本。
Updated sample implementing answer from @Peter Torr - MSFT. 更新了来自@Peter Torr - MSFT 的示例实现答案。
Working sample in which memory-mapped-file created from uwp app can be read by win32 process. 工作示例,其中从 uwp 应用程序创建的内存映射文件可以被 win32 进程读取。 Reading memory-mapped-file in uwp app created by win32 process still isn't working.
读取由 win32 进程创建的 uwp 应用程序中的内存映射文件仍然无法正常工作。
Yes it is supported, but if you're creating the object in a UWP context and opening it from a Desktop context then the Desktop process needs to explicitly use the namespace of the named object.是的,它受支持,但如果您在 UWP 上下文中创建 object 并从桌面上下文打开它,则桌面进程需要显式使用命名空间 object。
From within your UWP process, call GetAppContainerNamedObjectPath(nullptr, nullptr, ...)
to determine what that namespace is, and then add a backslash and your mapped file name to the end.在您的 UWP 进程中,调用
GetAppContainerNamedObjectPath(nullptr, nullptr, ...)
以确定该名称空间是什么,然后在末尾添加反斜杠和您的映射文件名。 It will be something like AppContainerNamedObjects\S-1-15-2-xxxxxxx\YourMappedName
它将类似于
AppContainerNamedObjects\S-1-15-2-xxxxxxx\YourMappedName
You should only need to do this once, unless you change your package name (including the publisher hash).您应该只需要执行一次,除非您更改您的 package 名称(包括发布者哈希)。 So once you have generated it, you can hard-code the value into your desktop app and forget about it.
因此,一旦您生成了它,您就可以将该值硬编码到您的桌面应用程序中,然后将其抛在脑后。
Note that if you do it the other way around - Desktop creates the object, and UWP opens it - then you don't need to worry about the namespace, but you have to modify the access control instead, which is trickier.请注意,如果您以相反的方式进行 - Desktop 创建 object,然后 UWP 打开它 - 那么您无需担心命名空间,但您必须改为修改访问控制,这比较棘手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.