Using WinUI 3 in a Visual Studio desktop MFC class library project - c#

To extend a third party MFC application I must create a desktop static MFC class library (i.e. dll). Using C++ I successfully completed the logic/backend portion of the project. With the aid of C++/winrt nuget package, I had a wealth of APIs that helped. Note my preferred language is C# with Visual Studio should that be relevant.
For the user interface I would like to completely use WINUI 3 instead of MFC APIs. Currently a desktop win32 WINUI solution must include a packaging project (i.e. MSIX) to get the required APP ID. This seems like a fundamental problem since I must produce a MFC dll and not a full blown application/exe install. If necessary I can wait (Not preferred) for Windows APP SDK 1.0, but I need to confirm this solves my problem and a release is coming.
Alternatively I may need to use WinRT XAML hosting API (XAML islands). This has limitation, but is this still the best/only viable option for WINUI in a C++ MFC desktop unpackaged app?
Basically how can I best utilize WINUI 3 in my MFC class library project?

Related

Build Pjsip windows sdk/.net 6 target dll

I am trying to create a pjsip dll and add it to an Uwp app. I have built a dll following this (working fine for WPF). Which gives an error while adding dll to the Uwp project saying unsupported-frameworks don't match as uwp targets Windows SDK. Creating a .net standard 2.0 class library as a bridge also didn't work.
At first, I found this solution. But this also produces more errors.
Now, I want to create a dll for Pjsip and use it in my UWP app. I am badly in need of a solution for creating windows SDK using pjsip or a suggestion regarding workarounds to use the current win32 .net framework targetted dll in the uwp project.
I have build pjsua2 dll and working fine using this link

How to use C# dll in UWP

I have a C# dll compiled in .net framework 2.0 and the library is not been updated by the vendor till now. In one of my desktop application C# i was using that and when i migrated the application to WPF, the same libraries where referred and working fine. Now, the application required new diversion, as it should be upgraded to UWP and the same dll i want to make use in that also. What is the best and easiest methods available in UWP to import.Net Framework 2.0 dll ?
Regards,
Lal
You can create a .NET Standard 2.0 library project that can reference the legacy library and you can then reference this .NET Standard 2.0 project from you UWP app.
In the .NET Standard library, you can write custom types that access the legacy library and provide a "middleware layer" between the UWP app and the legacy library.
What is the best and easiest methods available in UWP to import.Net Framework 2.0 dll ?
You can not direct consume any full .NET Class Library from UWP app, there is some security restrictions. UWP project can reference libraries such as Universal Windows Class Library,.NET Standard library, Windows Runtime Component and so on.
For solving this, since your app is for desktop devices and you already have a WPF app, I recommend you to convert the WPF app to UWP app by using Desktop Bridge. Or you could try to convert the old dll into one of above the libraries that can be referenced by UWP app. If you do only want to consume the .Net framework dll, you may try to create COM Proxy Stubs and work with them as communication layer, here is the official sample.
One solution for this is to make a windows service and use that dll in service. You can reference that service from UWP application in order to make all the API calls.

Is there a porting mode in Visual Studio 2012?

In short: I've got a library. It's not currently Windows Phone 8 compatible, and I'd like to make it so. What I'm wondering is does Visual Studio have an easy way of porting a current class library project from one version of .NET to another?
You can change your project to a portable class library (PCL). Normally you'd start with a PCL from scratch, but there is a hacky way to convert an existing library. Which is described in this blog post:
http://geekswithblogs.net/imilovanovic/archive/2012/08/31/vs2012---how-to-manually-convert-.net-class-library-to.aspx
Once your library is a PCL, you can enable windows phone as a target, and you'll get exceptions on everything that is not comparable.

How to add external non windows phone class library project reference to a windows phone project?

Hi there I am new to the windows phone development and I am trying to build a data driven application in which I have Created my BLL and EL and DAL ,which are all of windows phone class library type project.
I have also an extra project of type class library in my solution in which I have added the Reference to "MyGeneration.dOOdads.dll" file .
Now I want this project to be referenced in the windows phone app project.But when I try to add a reference ,The VS 2010 says...."Unable to add the selected project refernce.The project reference must be another silver light for windows phone project that is the same or the lower version ".
.
.
.
Kindly help me in this scenario. Thanks
That can't and won't work. The phone runtime only has access to a timy subset (well, sort-of) of the full .NET libraries, so any non-phone-7 library is extremely unlikely to operate at all. To stop this surprising people, only libraries built against that runtime are allowed to be referenced.
If possible, create a new project with the same c# files, targeting the phone 7 framework. Now reference this project. It is quite likely that some bits will fail to compile (demonstrating the fact that it also wouldn't have run), which can be rectified in a number if ways (#if blocks, alternative .cs files, etc).
You might also have some luck by making the existing project a "portable class library" - this, however, is the most restrictive subset of all the common frameworks, and is even less likely to still compile (without changes).
Using the Portable Class Library project, you can build portable assemblies that work without modification on the .NET Framework, Silverlight, Windows Phone 7, or Xbox 360 platforms.
(from MSDN)

How to Interop with Windows Runtime in .NET 4.5

I see this namespace:
System.Runtime.InteropServices.WindowsRuntime
Which provides interop between .NET and WindowsRuntime.
For instance, you can invoke a method in WindowsRuntime when you create a Metro application, as Metro uses WindowsRuntime, like
Windows.System.UserProfile.UserInformation
But when you create a normal .NET console application or WPF application, you can no longer directly reach WindowsRuntime namespaces such as Windows.System
I wonder if it were possible to invoke WindowsRuntime methods by using interop in the above-mentioned namespace.
A lot of thanks in advance!
A .NET console mode app or a WPF app are not Metro applications. They can only run on the 'regular' version of Windows. The traditional desktop in the case of Windows 8. So can't interop with WinRT, it isn't loaded in the process. Targeting WinRT requires selecting a specific Metro project template when you start your project.
You need to add this to the project file:
<PropertyGroup>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
</PropertyGroup>
For more details, see How to use specific WinRT API from Desktop apps.

Categories

Resources