3
votes

I have a Windows Store app project. In this project, I want to reference a Windows Runtime component written in C++. This component is available as a DLL + WinMD combination. However I am unable to figure out how to do this. I have tried adding a file reference from the app VS project to the DLL and WinMD files but I get an error saying the DLL could not be added. I then tried adding it as binary to output directory and still no luck.

I don't have the sources of this WinRT component. I know if I have the VS project for the WinRT component then I can simply add a reference from my app project to the WinRT component project and it all just works. But in case of loose WinMD/DLL files it doesn't work.

How can I do this?

1

1 Answers

4
votes

A WinRT component written in C# produces just one file, the winmd file which contains both the metadata and the implementation of the component. Furthermore, the same file can be used for all architectures (x86, x64 and ARM).

However, a WinRT component written in C++ produces two files - a winmd file which contains the metadata and a DLL file which contains the implementation. Furthermore, the DLL file is separate per architecture (one each for x86, x64 and ARM). It is for this reason that:

  • adding a reference to just the winmd file doesn't make sense (since the implementation is in DLL)
  • adding a reference to a single DLL file doesn't make sense a different DLL is required based on your project configuration/architecture

When you add a reference from your app VS project to the component VS project, the VS project system takes care of all of the above complexity for you. However when you don't have the sources/projects of the component, you can use the Extension SDK mechanism. if the DLL + WinMD combinations for all three architectures are packaged as an Extension SDK, then VS is able to correctly add the right configuration/architecture specific components into the app output.

For a real example of a C++ WinRT Extension SDK, take a look at the Bing Maps SDK. Install the SDK and then go to the following folder to see how the Extension SDK should be structured:

C:\Users\\AppData\Local\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\Bing.Maps.Xaml\1.313.0825.0

Note that you don't necessarily need to install the Extension SDK on every machine you want to use your project. Currently ESDKs are a machine-wide entity (unlike NuGet) but they can be made per project using the instructions here.