'I can't communicate between UWP app and Win32 app

Program.cs

using System;
using System.IO.MemoryMappedFiles;
using Windows.Storage;
using System.Threading;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace XBOXGameBarPoC_Win32
{
    static class Program
    {
        static void Main()
        {

            while (true)
            {
                using (var file = MemoryMappedFile.OpenExisting("XboxGameBarPoc_SharedMemory"))
                {

                    using (var writer = file.CreateViewAccessor(0, 10))
                    {
                        
                        writer.Write(0, 500);
                    }


                }
            }
        }
    }
}

MainPage.xaml.cs

using System.IO.MemoryMappedFiles;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Threading;
using Microsoft.Graphics.Canvas;
using Windows.UI;
using Windows.UI.Popups;
using System;

namespace XBOXGameBarPoC_UWP
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            MemoryMappedFile.CreateOrOpen("XboxGameBarPoc_SharedMemory", 0x644, MemoryMappedFileAccess.ReadWriteExecute);
        }

        private void canvasSwapChainPanel_Loaded(object sender, RoutedEventArgs e)
        {
            CanvasDevice device = CanvasDevice.GetSharedDevice();
            canvasSwapChainPanel.SwapChain = new CanvasSwapChain(device, (float)Window.Current.CoreWindow.Bounds.Width, (float)Window.Current.CoreWindow.Bounds.Height, 96);

            Thread renderThread = new Thread(new ParameterizedThreadStart(RenderThread));
            renderThread.Start(canvasSwapChainPanel.SwapChain);
        }

        private void RenderThread(object parameter)
        {
            CanvasSwapChain swapChain = (CanvasSwapChain)parameter;
            using (MemoryMappedFile memoryMappedFile = MemoryMappedFile.OpenExisting("XboxGameBarPoc_SharedMemory"))
            {
                using (MemoryMappedViewAccessor viewAccessor = memoryMappedFile.CreateViewAccessor())
                {
                    System.Numerics.Vector2 CenterTop;
                    CenterTop.X = 1920 / 2.0f;
                    CenterTop.Y = 0.0f;
                    int count = 0;
                    while (true)
                    {
                        using (CanvasDrawingSession ds = canvasSwapChainPanel.SwapChain.CreateDrawingSession(Colors.Transparent))
                        {
                            
                            viewAccessor.Read<int>(0, out count);
                            ds.DrawRectangle(count, 300, 150, 100, Colors.Red, 5);
                            canvasSwapChainPanel.SwapChain.Present();
                        }
                    }
                }
            }
        }
        struct Box
        {
            public float X;
            public float Y;
            public float Width;
            public float Height;
        }
    }
}

This issue is really killed my entire motivation. Nothing happens with those codes. I'm trying to communicate between Win32-UWP application. Win32 will constantly send information and UWP will draw based on that info. I tried almost everything, but still failing. I can attach project aswell if it's required.



Solution 1:[1]

I can't communicate between UWP app and Win32 app

MemoryMappedFile is not compatible with UWP platform. For Interprocess communication we suggest you use App services or Loopback here is official document that you could refer to.

I found you were using shared Memory to Interprocess communicate please refer this sharing named objects that could available in UWP platform.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nico Zhu - MSFT