Answered by:
How to manually add reference to runtime component?

Question
-
Hi,
Rather than add a project reference to a runtime component I need to manually add the reference to the binaries.
To test I created a "do nothing" runtime component and a blank XAML app. In the constructor for the app I added:
using namespace RuntimeComponent1; <-- added
MainPage::MainPage()
{
InitializeComponent();
Class1 c; <-- added
}
When a project reference is added everything works fine. So I removed the reference and copied the runtime component winmd file to another location, and then added a reference to that. It all compiles and I see the runtime component winmd and pri file in the output folder, but when I run the app I get error 0x80040154 (class not registered). I also included the DLL as a content type but that didn't resolve the issue.
Thanks for the help, greatly appreciated.
Monday, December 1, 2014 2:42 PM
Answers
-
Found the solution thanks to this post:
http://stackoverflow.com/questions/17864054/how-to-package-a-windows-runtime-component-for-distribution
The important bit:
"A component built with C++ provides separate .winmd and .dll files, and the DLL is what contains the details to register the component.
<Reference Include="component"> <HintPath>component.winmd</HintPath> <IsWinMDFile>true</IsWinMDFile> <Implementation>component.dll</Implementation> </Reference>"
Manually editing the proj file and adding an Implementation tag fixes the issue!
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Tuesday, December 9, 2014 1:35 AM
Monday, December 1, 2014 4:01 PM
All replies
-
Can you please explain more clearly what you are trying to do and why?
It sounds like you are trying to mix a normal DLL and a runtime component DLL, but the details and goal aren't clear.
Monday, December 1, 2014 3:18 PMModerator -
Hi Rob,
Sorry it all wasn't clear. In my app I want to add a reference to a Windows runtime component (written in C++) but I don't want to add it via a project reference. So I'm trying to find out how I go about adding it directly hence I tried adding a reference to the winmd file.
Since my last post I've been doing some digging and have found that Visual studio behaves differently in the two scenarios:
when the app is configured with a project reference visual studio adds an entry under HKCU\Software\Classes\ActivatableClasses\Package\{my package guid}\ActivatableClassId\{MyRuntimeComponent}
when the app is configured with a direct reference to the winmd file visual studio doesn't add the entry so GetFactory (within vcwinrt.cpp) fails.
So how can I get visual studio to still add this entry?
Thanks
Monday, December 1, 2014 3:28 PM -
Found the solution thanks to this post:
http://stackoverflow.com/questions/17864054/how-to-package-a-windows-runtime-component-for-distribution
The important bit:
"A component built with C++ provides separate .winmd and .dll files, and the DLL is what contains the details to register the component.
<Reference Include="component"> <HintPath>component.winmd</HintPath> <IsWinMDFile>true</IsWinMDFile> <Implementation>component.dll</Implementation> </Reference>"
Manually editing the proj file and adding an Implementation tag fixes the issue!
- Marked as answer by Herro wongMicrosoft contingent staff, Moderator Tuesday, December 9, 2014 1:35 AM
Monday, December 1, 2014 4:01 PM