Failed to add WinRT C ++ DLL project reference

SCENARIO:

I am creating a DLL project for Visual C ++ Direct X for Windows Store applications based on Visual Studio code sample for Visual Studio.

This should be a separate DLL project from my Windows Store application project, because I will use my XAML UserControl with Direct X renderer inside it both in the Windows 8 Metro application and in the Windows Phone version of the application.

PROBLEM:

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

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

I saw suggestions to compile a C ++ project using the / clr flag, but this is incompatible with:

  • / ZW flag required by some API in the project
  • header "wrl.h"
  • many other command line flags in project settings

Thus, the / clr flag is not an option in this situation.

QUESTION:

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

Thanks in advance.

+6
source share
2 answers

I solved the problem by re-creating the C ++ project as a Windows Runtime Component project. I originally created a project from the Class Library (Windows Store apps) template Class Library (Windows Store apps) . The Win RT template must have some configuration options that allow it to work.

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

This is due to @ user1610015's answer that I realized that I was actually developing my own Win RT code, not a managed code that makes me try this solution - thanks!

+6
source

The / ZW flag is for C ++ / CX projects. C ++ / CX is almost identical to managed C ++ syntax (C ++ / CLI), except that C ++ / CX is completely unmanageable. Perhaps this made you think that you were developing managed C ++ when you really didn't.

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

Another option is to talk to Windows Runtime without C ++ / CX. Although C ++ / CX simplifies Windows Runtime programming, this is not strictly necessary. You can also use the WRL library. Since the WRL library is pure C ++, it should also be used from C ++ / CLI.

+4
source

All Articles