Communication between UWP and Non UWP app
Asked Answered
R

5

13

Is it possible to have communication between uwp and non uwp apps. My non-uwp is a background task which provides a service. I want to call that non-uwp service in uwp app.

How to make that call? Is AppServiceConnection class available in non-uwp app?

Rampage answered 3/4, 2017 at 10:49 Comment(4)
Could an UWP app use pipes to communicate with a normal windows app?Rampage
UWP applications run in a container, so they have little access to the system they run on (for security concerns). You could use a windows service (which has access to most of the system) to do the communication for you. The windows service itself communicates with the UWP application via a WCF service (a "server", reachable for example via localhost:900/MyService.wcf/MyCall). Unfortunately, for this setup to work you must be able to configure the UWP application after install (see: #33260263)Wollis
You can communicate between apps by exposing endpoints just like a webservice. In fact it's easier this way IMO.Pompeii
I think this may help you: #40536876Grondin
G
19

Yes, non-UWP apps can use AppServices to communicate with UWP apps.

There is a sample here: https://github.com/Microsoft/DesktopBridgeToUWP-Samples/blob/master/Samples/AppServiceBridgeSample_C%2B%2B/cs/Win32Process_CPP/Win32Process_CPP.cpp

Gourde answered 13/4, 2017 at 1:31 Comment(2)
I was just talking to someone about this and I think this is an excellent Idea, and wonder if it's fast enough for serial ports? If I made a c++ program to talk over a com port, could the UWP app access it through that other program?Amador
Communicating over a COM port would be an alternative solution to AppService. I guess the trade-off here is between performance and ease-of-use/convenience.Gourde
C
3

I recommend the following sample by stefanwick. It's actually 4 parts with details and samples in code and in windows store: https://stefanwick.com/2018/04/06/uwp-with-desktop-extension-part-1/

Chifforobe answered 24/12, 2019 at 5:51 Comment(0)
S
0

i think i have the answer for you.

First off, if you want typical win32 functionality that is as easy to design as UWP, you should go for WPF, it pretty much uses the same designing framework but it can support all the things that UWP doesnt, traditional things like a Wndproc loop and sending messages to other applications can be supported on WPF.

Now, the way to get cross app communication on UWP, is by substructing the U from its name, it will stop being universal if you wish to go on with it.

Before i get deeper on why this is, i should explain how this whole Appservice thing works.

Appservice is a background service that can be called from other applications, its hosted under Backgroundhost.exe so this ensures it runs on a different thread than the app, thus preserving the sandbox, as i said it can be started by another app, its much like a class/method in your program that can be fired up by something outside, you can still change appfolder settings with them so you let your main app know what happened in this communication.

So in order for other apps, to access this app service they have to know the address of it, and in order to know that, you gotta hardcode it your self and include it on your folder as well as firing it up through your main APP, and this is only allowed on the desktop versions of UWP, so you see, in any case its better to use WPF.

And if the windows shop is the reason why you want to go with UWP then check out the guide on how to migrate a traditional dekstop app to the windows shop. https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-root

Furthermore if you are interested on the shiny new apis like the compact overlay that are only supported on UWP, you shouldnt, because there some ways to get it to work on normal desktop apps too.

Shelli answered 31/8, 2017 at 20:39 Comment(0)
S
0

One way for a UWP app to communicate with desktop app would be to use named pipes. But since a UWP app cannot directly communicate over named pipes you can use brokered component to achieve this. You can get more details on how to create brokered component here : https://learn.microsoft.com/en-us/windows/uwp/winrt-components/brokered-windows-runtime-components-for-side-loaded-windows-store-apps

Sized answered 8/11, 2018 at 9:39 Comment(0)
K
0

A simple way is to create Windows service (but read about their limitations) with WCF services or other RPC framework (I used WAMP Sharp) and call it from UWP app or from Win32 app. I assume it isn't the best practice, but for our case, it worked like a charm. Also, don't forget to turn on loopback for UWP app.

Koreykorff answered 4/3, 2019 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.