Using ATL/COM objects in UWP apps
Asked Answered
J

0

7

My company has many old projects that are written in vb6. We have some reusable software components which are written in ATL/C++. We're now considering to rewrite our app with UWP but it seems that UWP apps do not support the old COM technology. I am researching if there is a way to implement a COM object which also supports UWP. I understand that porting our old components to UWP Components would definitely work. But we do not want to maintain two version of common components because we have shipped many old software and we still provide software support. Some of those software have been used by our customers for more than 10 years. It is impossible to upgrade all software we have shipped.

I have come up with few possible solutions:

Desktop Bridge

I have found a phrase called "Packaged COM" which can be used by UWP apps with Desktop Bridge. This article, COM Server and OLE Document support for the Desktop Bridge, gives an example of calling an exe COM server from an UWP app. It seems to be a good solution if it also supprts InProcessServer. I did found something suspicious, InProcessServer, but it turns out that it is for WinRT components.

I have also tried to add the COM reference to the UWP project. The code can successfully refer to the COM object. However, it doesn't work at runtime. The UWP app has its own registry hive, therefor is won't load the COM object which is registered to the system registry. I'm thinking that if I add the registration information to the private hive of the UWP app and pack the COM dll along with the app, this may work. Just couldn't find any example.

ATL/COM

Since we have implemented our business logic into COM objects. The most viable solution would be upgrading our COM object to support UWP applications. WinRT components still use COM technology but implement the new interface IInspectable, I assume that the old ATL based COM object can be modified to support the calling convention of UWP if it implements IInspectable interface. I just don't have any clue to do this.

WRL

I found an MSDN article, How to: Create a Classic COM Component Using WRL, talking about using WRL project template to implement classes COM object which can be used in Win32 application as well as UWP apps.

It says:

You can use the Windows Runtime C++ Template Library (WRL) to create basic classic COM components for use in desktop apps, in addition to using it for Universal Windows Platform (UWP) apps

But I soon realise that WRL project template is no longer supported by Microsoft. All the download links of the project template I found on the web are no longer available.

C++/WinRT

This technology seems to be the successor of WRL. It seems promising but unfortunately have not yet been released.


To clarify few things from @Peter Torr:

(1) Do you want your app / COM object to be "pure" UWP (runs on all devices) or are you OK with fullTrust UWP (aka Desktop Bridge) that is Desktop-only? And (2) are the COM objects only for use with the app that ships them, or are they supposed to be used by other apps?

  1. My company uses Windows platform to provide PC-based industrial automation services(both hardware and software). So the answer is yes, we are happy with fullTrust UWP. Our products will only run on desktop. We just want to embrace the new technology and leverage the great UI framework of UWP.

  2. COM objects are for both new apps(UWP) and old software(some are vb6 based). We are happy with packaging COM objects with UWP apps and using system registered COM for old software as long as those COM objects are the same(built from the same code base).

Jacinthe answered 18/4, 2018 at 16:38 Comment(6)
UWP is thoroughly COM-powered at its core. But they dropped all the "bad parts", no more IDispatch and no more registry. And lots of spackle on top to hide the COM, implemented by the "language projection". WRL and C++/WinRT (it is ready) are the Hard Way to do it, no language projection. VB.NET, C#, Javascript or C++/CX are much less punishing. Create a UWP component with the "Windows Runtime Component" project template.Atli
FYI C++/WinRT is indeed a projection - it's actually a better projection than C++/CX (at least from the consumption side) since it is 100% pure C++, no language extensions required. More on-topic, let me ask a few folks around here. I believe Desktop Bridge should work for you.Numinous
Can you please clarify your question with a few things? (1) Do you want your app / COM object to be "pure" UWP (runs on all devices) or are you OK with fullTrust UWP (aka Desktop Bridge) that is Desktop-only? And (2) are the COM objects only for use with the app that ships them, or are they supposed to be used by other apps?Numinous
@HansPassant I have tried "Windows Runtime Component" project. It only works with UWP apps. I wnat the component can still be used by our old products which only support IDispatch based COM. Is there a way to make UWP component work as the old COM? We cannot afford to pack all old sotfware with DesktopBridge so that they can use UWP components.Jacinthe
@PeterTorr-MSFT Thank you for answering my question :). I have edited my question.Jacinthe
JFYI: You cannot use "the great UI framework of UWP" on a Desktop Bridge app. It needs to be a pure UWP to use the UI Framework.Chesney

© 2022 - 2024 — McMap. All rights reserved.