我无法在 UWP 应用程序和 Win32 应用程序之间进行通信
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;
}
}
}
这个问题真的扼杀了我的全部动力。这些代码没有任何反应。我正在尝试在 Win32-UWP 应用程序之间进行通信。 Win32 将不断发送信息,UWP 将根据该信息进行绘制。我几乎尝试了一切,但仍然失败。如果需要的话我也可以附上项目。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MemoryMappedFile
与 UWP 平台不兼容。对于进程间通信,我们建议您使用应用程序服务或官方的 Loopback 您可以参考的文档。我发现您正在使用共享内存进行进程间通信,请参阅此 共享可在 UWP 平台中使用的命名对象。
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.