How to call UWP API from converted Win32 app. (Desktop App Converter) - c++

I converted Win32 app (C++) to UWP one successfully.
But it can't work read/write file method, so I want to use UWP API from converted app.
Supported UWP APIs for converted desktop apps
I found this sentence "Most UWP APIs work well on converted desktop apps.".
But I can't find the way to call UWP API from converted Win32 app.
How to call UWP API from converted Win32 app ?
Thanks.

How to call UWP API from converted Win32 app ?
Actually, there are some samples in this offcial repository: DesktopBridgeToUWP-Samples
For example, the AppService Bridge Sample includes two projects: BackgroundProcess(Win32 Console application) and UWP(UWP app)
The BackgroundProcess project added reference to System.Runtime.WindowsRuntime and enable UWP AppService implementation, check ThreadProc function
The UWP project will use the new full trust capability to execute this Win32 application to consume the App service. See also Converted desktop app extensions
But it can't work read/write file method
In your scenario, you just need to complete UWP feature(StorageFile class) in the Win32 project and convert to the UWP app.

We have recently published a blog post about calling UWP APIs from Win32 processes. Those APIs generally can be called even without using the Desktop Bridge, but several are only applicable when using the UWP app model which the Desktop Bridge conversion provides:
https://blogs.windows.com/buildingapps/2017/01/25/calling-windows-10-apis-desktop-application
Thanks!

Related

Flutter Windows Desktop: Integrate with the File Activation API

I am looking for some guidance on implementing the Windows File Activation API with my Flutter App, that is, a user able to open a file associated with my App and have that file path passed to my app instance on startup and during runtime if the user opens a file whilst the app is already started.
I have found the following link from Microsoft that details how to achieve this within a UWP Application. However I have no been able to implement it completely with my limited knowledge of C++.
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/handle-file-activation
It seems that the File Activation API relies on the WinRT API. Is this already bundled with the Flutter runner project or does this need to be imported separately?
To hook into the File Activation API, I need to create a class that is derived from the Application class, Is it possible to achieve this whilst still having a reference to the Platform Channels provided so that the events can be passed into the Dart code?
Is it even a valid approach to use the WinRT API's or is there another API I have missed?

How to allow uiAccess in UWP application

I am invoking C++ UIautomation modules in my UWP application. The application is not able to extract control elements since it is not running in an elevated environment. How should I set up the manifest file or set my UWP app to be able to get access to ui elements of other applications.
I'd suggest that you could put the UIautomation modules into a console app and then launch the console as elevated from your UWP app using desktop bridge. You will also need to add the allowElevation capability into the manifest file.
For detailed steps, you could take a look at Stefan wick's blog- App Elevation Samples.

Windows Store App - remove fullTrustCapability

I'm developing a C++-Win32-app which should be deployed in the Microsoft Store. Unfortunately, since runFullTrustis added automatically as required capability, the program appears in Microsoft Store as follows: "This app can access all your files, peripheral devices, apps, programs and registry.", but I don't need all of those capabilities. Is there any possibility to get rid of the runFullTrust capability or to choose which capabilities are really needed?
If you want to publish the Win32 apps in Microsoft Store, and you must add restricted capability runFullTrust in the manifest.
Only UWP app can be published in the Microsoft Store,if you have an existing desktop application that was built using the .NET Framework (including WPF and Windows Forms) or C++ Win32 APIs, you can several options(Package your desktop application in an MSIX package, Use UWP APIs...) for moving to the UWP and Windows 10. The moved app called desktop bridge apps. You can see more details in document:
Move from a desktop application to UWP
The restricted capability runFullTrust is required for any desktop application that is delivered as an appx or msix package (as with the Desktop Bridge), and it will automatically appear in your manifest when packaging these apps using the Desktop App Converter (DAC) or Visual Studio. You can see this in document:
Restricted capabilities

CNG/BCrypt APIs in Windows IoT?

Does Windows IOT supports CNG/BCrypt APIs?
If possible, I'd like to have some references in case it does support.
It is supported. You can see that API support desktop apps and UWP apps.
But there seems no such UWP sample. You can reference "Encrypting Data with CNG" and "Typical CNG Programming" for desktop and create your own C++ UWP application.
Reference "Developing UWP applications for Windows IoT Core - C++"
Windows IoT Core also supports certain traditional Win32 app types such as Win32 Console Apps. There is an IoT Core C++ Console project template to make it easy to build such apps using Visual Studio.

How can I call an UWP API from a C++ desktop application

I would like to access Bluetooth LE devices using the corresponding UWP APIs. However, my application is a "classic" C++ application (3D game) that can't run as a UWP app. Is there a way to do that? Accorind to enter link description here these APIs are published, but I don't know the steps to access them I have only found some posts for Windows 8/8.1 apps that include the Windows.winmd and Platform.winmd metadata files and set the /ZW compilation flag, but this doesn't seem to apply to Windows 10.
You should be able to do this, as the Bluetooth classes (e.g., BluetoothLEAdvertisement) are marked up with DualApiPartitionAttribute (callable from desktop and UWP apps).
Using one of the older Win8.1 desktop samples should give you a good starting point for calling the APIs without requiring /ZW or referencing the winmd files. A good example is the desktop toast API sample.
If you go that route, you can use classic COM to create the UWP/WinRT classes via WRL helpers.
You can use the web that you make a web server and the C++ application use the same server and if UWP send the info to server then it will send the info to C++ application.
To safe,the UWP can't use the desktop app.