Universal Windows Platform (UWP). It has delicate UI by XAML. But it can not support a lot of WIN32 function. That is why we need UWP extention to unlimited it ability.
- Paltform: visual studio 2019
- Function describe: UWP through Windows Desktop Extensions for the UWP tool side loading winform.
- Compile sample: UWP can not run at any CPU, and target should set Windows Application Packaging Project.

For just sideload other app
This UWP_extention can side loading winform by using
FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync().Modify WapProj/Package.appxmanifest by adding extensions in Windows Application Packaging Project.
<Packagexmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"IgnorableNamespaces="uap mp desktop rescap"> <Applications>
<ApplicationId="App"Executable="$targetnametoken$.exe"EntryPoint="$targetentrypoint$">
<uap:VisualElementsDisplayName="WapProj_HotTab_Win10"Description="WapProj_HotTab_Win10"BackgroundColor="transparent"Square150x150Logo="Images\Square150x150Logo.png"Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTileWide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreenImage="Images\SplashScreen.png" />
</uap:VisualElements>
<Extensions>
<uap:ExtensionCategory="windows.appService">
<uap:AppServiceName="SampleInteropService" />
</uap:Extension>
<desktop:ExtensionCategory="windows.fullTrustProcess"Executable="CollectDataAP\CollectDataAP.exe" />
</Extensions>
</Application>
</Applications>Add UWP extension in UWP/Reference

Add and cover this in UWP/App.xmal.cs
sealedpartialclassApp:Application{publicstaticBackgroundTaskDeferralAppServiceDeferral=null;publicstaticAppServiceConnectionConnection=null;publicstaticboolIsForeground=false;publicstaticeventEventHandler<AppServiceTriggerDetails>AppServiceConnected;publicstaticeventEventHandlerAppServiceDisconnected;privatevoidApp_LeavingBackground(objectsender,LeavingBackgroundEventArgse){IsForeground=true;}privatevoidApp_EnteredBackground(objectsender,EnteredBackgroundEventArgse){IsForeground=false;}/// <summary>/// Initializes the singleton application object. This is the first line of authored code/// executed, and as such is the logical equivalent of main() or WinMain()./// </summary>publicApp(){this.InitializeComponent();this.Suspending+=OnSuspending;this.EnteredBackground+=App_EnteredBackground;this.LeavingBackground+=App_LeavingBackground;}/// <summary>/// Handles connection requests to the app service/// </summary>protectedoverridevoidOnBackgroundActivated(BackgroundActivatedEventArgsargs){base.OnBackgroundActivated(args);if(args.TaskInstance.TriggerDetailsisAppServiceTriggerDetailsdetails){// only accept connections from callers in the same packageif(details.CallerPackageFamilyName==Package.Current.Id.FamilyName){// connection established from the fulltrust processAppServiceDeferral=args.TaskInstance.GetDeferral();args.TaskInstance.Canceled+=OnTaskCanceled;Connection=details.AppServiceConnection;AppServiceConnected?.Invoke(this,args.TaskInstance.TriggerDetailsasAppServiceTriggerDetails);}}}/// <summary>/// Task canceled here means the app service client is gone/// </summary>privatevoidOnTaskCanceled(IBackgroundTaskInstancesender,BackgroundTaskCancellationReasonreason){AppServiceDeferral?.Complete();AppServiceDeferral=null;Connection=null;AppServiceDisconnected?.Invoke(this,null);}
....Add and cover in UWP/MainPage.xmal.cs
publicMainPage(){this.InitializeComponent();// ApplicationView.PreferredLaunchViewSize = new Size(200, 200);// ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.PreferredLaunchViewSize;}protectedasyncoverridevoidOnNavigatedTo(NavigationEventArgse){base.OnNavigatedTo(e);if(ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract",1,0)){//for connect or disconnect event//App.AppServiceConnected += MainPage_AppServiceConnected;//App.AppServiceDisconnected += MainPage_AppServiceDisconnected;//for sideload appawaitFullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();}}/// <summary>/// When the desktop process is disconnected, reconnect if needed/// </summary>privateasyncvoidMainPage_AppServiceDisconnected(objectsender,EventArgse){awaitDispatcher.RunAsync(CoreDispatcherPriority.Normal,()=>{Reconnect();});}/// <summary>/// Ask user if they want to reconnect to the desktop process/// </summary>privateasyncvoidReconnect(){if(App.IsForeground){MessageDialogdlg=newMessageDialog("Connection to desktop process lost. Reconnect?");UICommandyesCommand=newUICommand("Yes",async(r)=>{awaitFullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();});dlg.Commands.Add(yesCommand);UICommandnoCommand=newUICommand("No",(r)=>{});dlg.Commands.Add(noCommand);awaitdlg.ShowAsync();}}
.......if can not find entrypoint, can see this for more information
https://stackoverflow.com/questions/77065216/dep0700-registration-of-the-app-failed-while-uwp-extension-launch-consult-app/77493220#77493220
Go to BelaunchedApp/reference and add those file

Add and cover sildload_app/program
classProgram{staticprivateAppServiceConnectionconnection=null;staticvoidMain(string[]args){InitializeAppServiceConnection();strings_res;while((s_res=Console.ReadLine())!=""){inti_res=int.Parse(s_res);if(i_res==1){doublea=1,b=2;Console.WriteLine(a+" + "+b+" = ");Send2UWP(a,b);}}}/// <summary>/// Open connection to UWP app service/// </summary>staticprivateasyncvoidInitializeAppServiceConnection(){connection=newAppServiceConnection();connection.AppServiceName="SampleInteropService";connection.PackageFamilyName=Package.Current.Id.FamilyName;connection.RequestReceived+=Connection_RequestReceived;connection.ServiceClosed+=Connection_ServiceClosed;AppServiceConnectionStatusstatus=awaitconnection.OpenAsync();if(status!=AppServiceConnectionStatus.Success){//In console, something wrongConsole.WriteLine(status.ToString());//In app, something went wrong ...//MessageBox.Show(status.ToString());//this.IsEnabled = false;}}/// <summary>/// Handles the event when the desktop process receives a request from the UWP app/// </summary>staticprivateasyncvoidConnection_RequestReceived(AppServiceConnectionsender,AppServiceRequestReceivedEventArgsargs){// retrive the reg key name from the ValueSet in the requeststringkey=args.Request.Message["KEY"]asstring;if(key=="abcd"){// compose the response as ValueSetValueSetresponse=newValueSet();response.Add("GOOD","KEY IS FOUNDED ^^");// send the response back to the UWPawaitargs.Request.SendResponseAsync(response);}else{ValueSetresponse=newValueSet();response.Add("ERROR","INVALID REQUEST");awaitargs.Request.SendResponseAsync(response);}}/// <summary>/// Handles the event when the app service connection is closed/// </summary>staticprivatevoidConnection_ServiceClosed(AppServiceConnectionsender,AppServiceClosedEventArgsargs){//In console, connection to the UWP lost, so we shut down the desktop processConsole.WriteLine("UWP lost connection! Please restart.");Console.ReadLine();Environment.Exit(0);//In app, connection to the UWP lost, so we shut down the desktop process//Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>//{// Application.Current.Shutdown();//}));}staticprivateasyncvoidSend2UWP(doublea,doubleb){// ask the UWP to calculate d1 + d2ValueSetrequest=newValueSet();request.Add("D1",a);request.Add("D2",b);//start sendingAppServiceResponseresponse=awaitconnection.SendMessageAsync(request);//get responsedoubleresult=(double)response.Message["RESULT"];Console.WriteLine(result.ToString());}}- https://stefanwick.com/2018/04/16/uwp-with-desktop-extension-part-3/
- https://www.cnblogs.com/manupstairs/p/14178931.html
- https://github.com/StefanWickDev/UWP-FullTrust/tree/master/UWP_FullTrust_3
- https://freetion26.medium.com/uwp%E9%80%8F%E9%81%8Eappserviceconnection%E5%92%8Cwin32-process%E6%BA%9D%E9%80%9A%E5%8F%96%E5%BE%97%E7%B3%BB%E7%B5%B1%E8%B7%AF%E5%BE%91%E4%B8%8B%E6%AA%94%E6%A1%88%E5%88%97%E8%A1%A8-981dd0765e52


