Could not add reference to WinRT C++ DLL project
Asked Answered
I

2

8

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.

Inurbane answered 25/12, 2012 at 7:46 Comment(0)
I
8

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!

Inurbane answered 28/12, 2012 at 10:36 Comment(0)
T
5

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.

Theisen answered 25/12, 2012 at 9:40 Comment(1)
Thank you for this info - I had no idea that I wasn't developing unmanaged code. I didn't end up needing to try Tlbimp.exe - see my answer above.Inurbane

© 2022 - 2024 — McMap. All rights reserved.