locked
Using managed classes in CX/C++ windows runtime component?

    Question

  • So I have a managed class, written in .net, and I want to use an object defined by said class in my windows runtime component written in C++/CX.

    I can reference the managed library just fine, the compiler even recognizes the class (says public ref class Boar) but when I try to create a Boar object in the CX component, the compiler eventually says that class does not exist.

    So I am guessing this is impossible? Or is there any other way of doing this?


    • Edited by mcosmin Sunday, January 11, 2015 9:30 AM
    Sunday, January 11, 2015 9:07 AM

Answers

  • There is no .NET Framework types in C++/CX, just WinRT data types. E.g. String^ is actually a wrapper of HSTRING, not System::String. So you can't create a System::String variable to store a string return value or construct a System::String to pass to the C++/CLI library. You can read further at https://social.msdn.microsoft.com/forums/windowsapps/en-us/0aec2f93-de7e-4f2b-8090-17ceb34ed759/differences-between-ccli-and-winrt-c for more differences.

    You can try rewrite the C++/CLI component to target WinRT (make it a WinRT component). 



    Visual C++ MVP


    Sunday, January 11, 2015 8:20 PM
  • As I understand it managed WinRT apps can consume native C++/CX libraries and their exports but not the other way around. I've encountered this same situation and opted to port my .Net assembly to C++/CX.
    Monday, January 12, 2015 5:21 PM

All replies

  • There is no .NET Framework types in C++/CX, just WinRT data types. E.g. String^ is actually a wrapper of HSTRING, not System::String. So you can't create a System::String variable to store a string return value or construct a System::String to pass to the C++/CLI library. You can read further at https://social.msdn.microsoft.com/forums/windowsapps/en-us/0aec2f93-de7e-4f2b-8090-17ceb34ed759/differences-between-ccli-and-winrt-c for more differences.

    You can try rewrite the C++/CLI component to target WinRT (make it a WinRT component). 



    Visual C++ MVP


    Sunday, January 11, 2015 8:20 PM
  • As I understand it managed WinRT apps can consume native C++/CX libraries and their exports but not the other way around. I've encountered this same situation and opted to port my .Net assembly to C++/CX.
    Monday, January 12, 2015 5:21 PM