简体   繁体   English

我无法在 UWP 应用程序和 Win32 应用程序之间通信

[英]I can't communicate between UWP app and Win32 app

Program.cs程序.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 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-UWP 应用程序之间进行通信。 Win32 will constantly send information and UWP will draw based on that info. Win32 将不断发送信息,UWP 将根据该信息绘制。 I tried almost everything, but still failing.我几乎尝试了一切,但仍然失败。 I can attach project aswell if it's required.如果需要,我也可以附加项目。

I can't communicate between UWP app and Win32 app我无法在 UWP 应用程序和 Win32 应用程序之间通信

MemoryMappedFile is not compatible with UWP platform. MemoryMappedFile与 UWP 平台不兼容。 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.我发现您正在使用共享 Memory 进行进程间通信,请参阅此共享命名对象,该对象可在 UWP 平台中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以从 UWP 应用程序的进程外后台任务中启动 FullTrust Win32 应用程序吗? - Can I launch a FullTrust Win32 app from within a UWP app's out-of-process background task? 我的Win32 App如何从UWP App窃取焦点? - How Can My Win32 App Steal Focus From My UWP App? 内存映射文件是否作为 uwp 应用程序和 win32 进程之间的 ipc 支持 - Is Memory-mapped-files as ipc between uwp app and win32 process supported 从主UWP进程终止UWP应用的Win32进程,或向其发送消息 - Terminate the win32 process of UWP app from main UWP process, or send message to it 如何在Win32应用程序中托管ac#控件? - How can I host a c# control in a win32 app? 如何通过后台 Win32 进程使用全局快捷方式启动 UWP 应用程序? - How to start a UWP app with a global shortcut through a background Win32 process? 如何从 UWP 应用程序中使用命令行 arguments 实现启动 win32 exe? - How do you implement Launching a win32 exe with command line arguments from an UWP app? 在win服务和win app之间进行通信 - communicate between win service and win app LaunchFullTrustProcessForCurrentAppAsync 杀死 win32 应用程序 - LaunchFullTrustProcessForCurrentAppAsync kills win32 app 如何在 UWP 中获得对 StorageFile 或 StorageFolder 的 FILE_WRITE_ATTRIBUTES 访问权限的 Win32 HANDLE? - How can I get a Win32 HANDLE with FILE_WRITE_ATTRIBUTES access for a StorageFile or StorageFolder in UWP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM