locked
How to use C# Metro type libraries (DLLs) in Visual C++ Metro application ?

    Question

  • Is it possible to use the controls defined in the C# library (Metro Style ) in Visual C++ Metro Style applications? If possible, how to do it?
    Monday, September 26, 2011 11:42 AM

Answers

  • To clarify, Metro style apps in C++ do not use managed C++/CLI.  They use unmanaged C++/Cx.  Unlike C++/CLI apps, they can't directly consume normal managed assemblies.
    XAML controls can be created in either C#/VB or C++ by inheriting from Windows::Ui::Xaml::Controls::Control and exporting the new class as a WinRT component (build as WinMD and export as sealed).  The new control can be used in either C#/VB or C++.
    Reference the control in the .xaml file the same way as any other control:
    xmlns:cc="using:MyCustomControlLibrary"
    
    ...
    
    
    <cc:MyControl Content="My custom control" HorizontalAlignment="Left" VerticalAlignment="Top" />
    
    Tuesday, September 27, 2011 9:46 PM
    Owner

All replies

  • Is it possible to use the controls defined in the C# library (Metro Style ) in Visual C++ Metro Style applications? If possible, how to do it?
    It's the same as you would do it in .NET between C++/CLI and C# (or between any two CLR languages).
     
    Create a C# Metro class library project, and make a reference to it in your C++/CX project.
     

    David Wilkinson | Visual C++ MVP
    • Proposed as answer by Bob_Bao Tuesday, September 27, 2011 3:01 AM
    Monday, September 26, 2011 1:54 PM
  • since the C++ Metro Stype Project is a C++/CLI project, so you could simply do it. Just right click on the C++ project and click the References... But I recommend you to build you r C# library as WinMD output, please read it first: http://mdavey.wordpress.com/2011/09/14/build-windows-runtime-winmd-files/

    And this thread may help you also: http://social.msdn.microsoft.com/Forums/en-us/winappswithcsharp/thread/d24fd82f-a927-427e-8522-84070d6c1117 and thi session: http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-531T


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, September 27, 2011 3:46 AM
  • To clarify, Metro style apps in C++ do not use managed C++/CLI.  They use unmanaged C++/Cx.  Unlike C++/CLI apps, they can't directly consume normal managed assemblies.
    XAML controls can be created in either C#/VB or C++ by inheriting from Windows::Ui::Xaml::Controls::Control and exporting the new class as a WinRT component (build as WinMD and export as sealed).  The new control can be used in either C#/VB or C++.
    Reference the control in the .xaml file the same way as any other control:
    xmlns:cc="using:MyCustomControlLibrary"
    
    ...
    
    
    <cc:MyControl Content="My custom control" HorizontalAlignment="Left" VerticalAlignment="Top" />
    
    Tuesday, September 27, 2011 9:46 PM
    Owner
  • Hi ,

    I have used Dependency Properties in my custom control created in C#. While referring that control in Visual C++ ( Control exported as WinMD and export as sealed) the following error was thrown.

    " Type 'CustomControlName' contains externally visible field 'DependencyProperty_Variable'. Fields may only be exposed by structures".

    Any solution ?


    Friday, September 30, 2011 12:41 PM