How to create a COM object in a UWP application? (C#)

前端 未结 4 1049
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 08:17

Question: How to create COM object in a Universal Windows Platform (UWP) application?

Motivation: I want to switch from WPF to UW

相关标签:
4条回答
  • 2020-12-25 08:40

    As you note, it isn't possible to access arbitrary COM objects from a Universal Windows app. It is likely your third party libraries also use API which aren't available directly from within the Windows Runtime.

    Assuming you intend to sideload the app rather than deploying through the store you can call your COM objects and libraries indirectly through a Brokered Windows Runtime Components for side-loaded Windows Store apps (docs for Windows 8.1 but still valid for Windows 10). This feature is designed for enterprise apps to provide a modern UI while still having access to existing functionality.

    If you want to deploy through the store then you will stay restricted to the API allowed in the Windows Runtime context and can't use a Brokered Windows Runtime Component.

    If your main goal is to deploy through the store and you don't need to otherwise convert to a Universal app then take a look at the upcoming Windows Bridge for Classic Windows apps (also called ”Project Centennial”) which will allow packaging your current .Net project for store deployment and will allow extending it to use some UWP capabilities.

    0 讨论(0)
  • 2020-12-25 08:52

    On the other site, the UWP/ WinRT way seems the only way MS is going on there OS for security reasons. I don't know if the Sandbox would be able to detect on a old school custom COM object called from allowed object a not allowed action. I hope this is possible for the Sandbox.

    0 讨论(0)
  • 2020-12-25 09:02

    UWP or Windows Universal Application does not sound like the right solution here. UWP does not allow for COM because it is not available on all platforms. I am assuming that you would like to use the windows store for a deployment mechanism of your current WPF application. Windows 10 does offer what microsoft calls a bridge for WPF applications where you can deploy your WPF application as a appx package in the windows store.

    Hopefully you will have very little to rewrite with this solution

    For more information on how to Deploy a WPF application in an APPx file see the following video. https://channel9.msdn.com/Events/Build/2015/2-692

    0 讨论(0)
  • You certainly know that UWP apps are sand-boxed apps, they need a permission to do almost everything. For example, they can't access the entire file system, but only a sandboxed storage area. When you want an app to be published in the Windows Store, the App Certification Kit checks that your app doesn't do what it is not allowed to do.

    The link you provide (Win32 and COM for Windows Runtime apps...) describes a list of allowed WIN32/COM calls. Microsoft allows you to call these methods, and only them.

    Using a Visual Basic COM Object seems to be out of reach...

    This is about security restrictions, but also about available features: for example, there is no way to register a COM object on a Windows Phone (regsrvr32).

    You can call any COM object (or Win32 API) in C# in a WPF application, and in C++ of course. Not sure what happens if you try to copy/paste this kind of code in a UWP app. You'll may be able to run the code on Windows Desktop, but you won't certainly be able to submit your app to the Windows Store, and it won't work on other UWP platforms. Microsoft doesn't give many details about calling COM objects from UWP app.

    I guess that UWP is not very well suited/adapted/compatible with "old" COM objects... I'm not sure what this migration from WPF to UWP would bring you?

    0 讨论(0)
提交回复
热议问题