Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Lets assume that My PCL library is called A.dll.
  • My WinRT component is called B.winmd.
  • Now, B.winmd uses A.dll internally and creates a wrapper around it.

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?

like image 930
Avi Avatar asked Dec 20 '25 01:12

Avi


1 Answers

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.

like image 165
Hans Passant Avatar answered Dec 23 '25 07:12

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!