Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not add reference to WinRT C++ DLL project

THE SCENARIO:

I am making a [edit: native WinRT] C++ Direct X DLL project for Windows Store apps based on the "Direct3D App" Visual Studio code sample.

This must be a separate DLL project from my Windows Store App project because I will be using my XAML UserControl with Direct X renderer inside it both in the Windows 8 Metro app and a Windows Phone version of the app.

THE PROBLEM:

I cannot reference the C++ project in the C# Windows Store app project. Visual Studio refuses with the following words:

A reference to <project-name> could not be added.

I've seen suggestions to compile the C++ project using the /clr flag, but this is not compatible with:

  • the /ZW flag required by some API within the project
  • the "wrl.h" header
  • a multitude of other command-line flags in the project settings

So the /clr flag does not appear to be an option in this situation.

THE QUESTION:

How can I reference the C++ project so that I can use my XAML Direct X renderer within the C# Windows Store App project? Or is there a better alternative?

Thanks in advance.

like image 997
Brett Avatar asked Dec 25 '12 07:12

Brett


2 Answers

I solved the problem by re-creating the C++ project as a Windows Runtime Component project. I had originally created the project from the Class Library (Windows Store apps) template. It must be that the Win RT template has some configuration settings which enable it to work.

After making this change, the project could be added as a reference in the C# project.

It is because of @user1610015's answer that I realised I was actually developing native Win RT code, not managed code, which lead me to try this solution - thanks!

like image 121
Brett Avatar answered Oct 20 '22 04:10

Brett


The /ZW flag is for C++/CX projects. C++/CX is almost identical in syntax to managed C++ (C++/CLI), except that C++/CX is completely unmanaged. This may be what made you think you were developing managed C++, when in fact you weren't.

I haven't used C++/CX, but from what I've heard, Windows Runtime classes are COM classes. So I think you can use the TlbImp.exe tool from the Windows SDK to create a managed DLL from your unmanaged DLL, which you can then reference from your C# project. Try it and let me know if it works.

Another option is to talk to the Windows Runtime without C++/CX. While C++/CX makes Windows Runtime programming a lot easier, it's not strictly necessary. You can also use the WRL library. Since the WRL library is pure C++, it should also be usable from C++/CLI.

like image 45
user1610015 Avatar answered Oct 20 '22 04:10

user1610015