Avi
Avi

Reputation: 2383

Including a PCL library DLL in a C++ winrt Project

I created Portable Class Library that I want to use in various WinRT projects. I can use this PCL dll in C# Winrt Apps, VB WinRT Apps, silverlight and Windows Phone. But for some reason, I can't successfully add the library to my C++ project. The error that I get when I try this is:

Could not add a reference to file 'C:\Users\xyz\pqr.dll' because it is neither a .NET assembly nor a registered ActiveX control.

I saw the same question on SO earlier and the OP posted a solution that seems to work for him. I tried to find the following line as the original question suggested but I can't find it in the vcxproj file.

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

Since I can't post a comment on the original question, I figured I should post another question here.

Any Ideas?

Edit: My project setup looks something like this:

Now when I want to create a Store App C in C++, I have to add references to both A.dll and B.winmd in my project C. If I just include B.winmd, I get a runtime exception the first time something from A.dll is used. What am I doing wrong?

Upvotes: 3

Views: 1578

Answers (2)

Hans Passant
Hans Passant

Reputation: 942368

A C++ application does not know how to execute managed code. If you want to create a library using C# and make it available to another runtime environment like C++ or Javascript then you have to create a Windows Runtime Component project. Its public interface is limited to WinRT compatible types to allow the interop between runtime environments to work. Lots of other little rules.

The MSDN starter page is here.

Upvotes: 2

Filip Skakun
Filip Skakun

Reputation: 31724

Your message should be a good hint there - a PCL library is a .NET library. WinRT projects need WinRT components. You need to create a .NET-based WinRT component that will wrap your PCL library to make it usable in non-.NET languages.

Upvotes: 0

Related Questions