Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.. Is ipc via memory-mapped-files supported in uwp, if yes, what is the proper way to do it??

Minimal reproduceable sample.

Update 1

Updated sample implementing answer from @Peter Torr - MSFT.

Update 2

Working sample in which memory-mapped-file created from uwp app can be read by win32 process. Reading memory-mapped-file in uwp app created by win32 process still isn't working.

like image 229
Soumya Mahunt Avatar asked Sep 10 '25 03:09

Soumya Mahunt


1 Answers

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.

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. It will be something like 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). 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.

like image 150
Peter Torr - MSFT Avatar answered Sep 12 '25 18:09

Peter Torr - MSFT