7

Assuming that I am on Windows 8+ and I have a Win32/C App. Can my Win32 App call into WinRT API?

Richard Chambers
  • 16,643
  • 4
  • 81
  • 106
Kenny Lim
  • 1,193
  • 1
  • 11
  • 31
  • 1
    @JonathanPotter: putting [this](http://blogs.msdn.com/b/cdndevs/archive/2013/10/02/using-windows-8-winrt-apis-in-net-desktop-applications.aspx) and [this](http://www.codeproject.com/Articles/12673/Calling-Managed-NET-C-COM-Objects-from-Unmanaged-C) together suggests that it should be possible. Is there a catch I'm not seeing? – Harry Johnston Sep 17 '14 at 01:38
  • @HarryJohnston: Interesting link. Perhaps it is possible in some limited way. You should make this an answer. – Jonathan Potter Sep 17 '14 at 01:45
  • Which API do you wish to call? – David Heffernan Sep 17 '14 at 07:29

1 Answers1

6

Short answer - yes: How to: Activate and Use a Windows Runtime Component Using WRL

Long answer: Windows Runtime is heavily based upon COM technology. The Windows Runtime components are actually some kind of COM objects. So the common rules for instantiating and using COM objects apply to Windows Runtime components.

First, you must initialize the Windows Runtime environment. There's a useful class called RoInitializeWrapper you can use to do this. Then, you use an activation factory to obtain a pointer to the Windows Runtime component's interface. You work with the interface, and when you finished, you must uninitialize the Windows Runtime environment by destroying your RoInitializeWrapper.

Alovchin
  • 663
  • 3
  • 9
  • This article has lots of examples - https://msdn.microsoft.com/en-us/library/windows/desktop/mt759320(v=vs.85).aspx(d=robot) - The focus of the article is on Windows Information Protection but it shows both C++ / CX and COM activation examples with plain jane C++. – Norm Estabrook Sep 18 '17 at 15:52