How to get the simplest Windows message in a UWP XAML MVVM application?

My big picture problem: I need to send a signal from a Windows 10 desktop application (or service, really) to a UWP XAML MVVM application on a single instance / OS machine.

I used semaphores in the global namespace, but they do not work at all on UWP (for security reasons, perhaps by design). There is no joy.

I tried UWP sockets and this works with UWP as a listener only if the client is on a remote machine. Is this a security solution too? No idea. Exempting the application from the loopback restriction does not help, since this only applies if the UWP application is the client that is executing the request. There is no joy.

OK, so I left a Windows message in a specific window on OS ...

My test application is an example of AdventureWorks for UWP on GitHub. How to do this to process a Windows message sent from another process? I'm at a dead end.

Below is the code for my test client.

Question: How do I handle this message in AdventureWorks? It is important to keep the code changes to a minimum, but I'm currently stuck and not going to continue. (It seems to be a secret secret ...)

Please, help! Sample code.

class Program { [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, String lpWindowName); [DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern uint RegisterWindowMessage(string lpString); [DllImport("kernel32.dll")] static extern uint GetLastError(); static void Main(string[] args) { const string lpClassName = "ApplicationFrameWindow"; const string lpWindowName = "AdventureWorks.Shopper"; IntPtr hwnd = FindWindow(lpClassName, lpWindowName); uint messageId = RegisterWindowMessage("MetaAutomationMessage"); int sendMessageResult = SendMessage(hwnd, messageId, IntPtr.Zero, IntPtr.Zero); Console.WriteLine(string.Format("Message result is '{0}', ", sendMessageResult)); uint lastError = GetLastError(); Console.WriteLine(string.Format("GetLastError result is '{0}', ", lastError)); } } 
+5
source share
2 answers

The UWP application is isolated, so you cannot send or receive messages, etc. by design in a Win32 application.

There are several potentially less desirable parameters, such as enabling loopback communication through a local socket: fooobar.com/questions/554975 / ... (maybe this is what you tried - this is not clear).

However, the UWP application may not be the best platform choice today if you need to communicate with a locally installed service in a universal application.

There are several ways to launch the application and provide some data as part of the launch, but the Win32 service should not start interactive user processes (so that would not be a good way to transfer data).

You might want to create your application as a WPF application if you need to communicate with a Win32 application / service.

+1
source

Connecting the Windows 10 UWP App service may be one option for sending a set of key values โ€‹โ€‹between UWP applications.

Link: https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service

+1
source

Source: https://habr.com/ru/post/1241532/


All Articles