locked
C++ and WinRT

    Question

  • Even after searching, I'm still a bit confused. My question is, when is the approximate time they expect that the 'C++ for WinRT' syntax will be finalized, and what would be the best route now to learn it if all you have written is native code?

    Thanks.

    Wednesday, October 26, 2011 4:28 AM

Answers

  • My two cents...

    C++ uses a "Component Extensions" syntax (compiler switch /Cx) that is based on C++/CLI, an ECMA standard that was pushed by Microsoft through Herb Sutter.  The C++/CLI syntax is solid, in my opinion, and you'd be fine in reading some of the C++/CLI documentation or a book such as C++/CLI in Action or one of the APress books.

    Saying that, the differences are minimal--one I can remember from the BUILD sessions by Herb Sutter is the gcnew versus the ref new to initialize a reference class.  Notice that although recycling the syntax, the "hat" notation has a different meaning in WinRT than in the CLR.  In WinRT you'll always be referring to a WinRT compatible type which is not a managed type in the sense of "it is not garbage collected."  The C++ /Cx syntax always produces native code (again, native code does not mean portable code :-) and it is syntactic sugar over the WinRT.  You could always access the lower level of the WinRT via COM (as in COM "Reloaded") and the WRL.

    Finally, to answer your question, I would consider the syntax as finalized--many benefits by recycling the C++/CLI syntax and integrating it with the WinRT.

    Since you come from native code, your mileage will vary, depending on the UI frameworks you've worked with.  I'd recommend downloading the samples after installing the Windows 8 Developer Preview with Tools and Apps (x64), since the other version (Windows 8 Developer Preview with Apps + standalone version of Visual Studio 11 Dev Preview) won't run the Metro style apps--even though it has the templates, the compilation fails.  Perhaps you'll be able to install it and make it run, but I and other developers have been bitten by this "mirage".

    Summarizing:

    A good book on XAML.  All the books out there are about WPF and you learn XAML by learning WPF, but the concepts port to Metro. My recommendation is to look at WPF 4 Unleashed.  This book contains the latest updates to XAML (excluding what changed in Visual Studio 11) and it is a great reference for XAML.  The XAML portion, concepts, data binding, routed events, etc., is reusable in Metro, and several if not most of the WPF concepts are in Metro.

    A good book on C++/CLI to extract the syntax.  Manning's C++/CLI in action is an easy read.  The sections that will not be applicable are the ones where you interface with .NET.  now the interfacing is with WinRT. You can find other, simpler references, and if you're familiar with C#, several of the concepts have been adopted in C++/Cx verbatim (e.g., sealed keyword).  

    If you want to dive into COM to do lower level programming, be my guest.  Albeit some books may be applicable for COM and ATL (using the COM smart pointers, wrappers around enumerations, collections, lifetime of COM objects, factories, apartments, I think you'd be better off with the documentation and the forums for now, but if you must, check Don Box's classic Essential COM and ATL Internals by Chris Sells, Brent Rector, Chris Tavares and Kirk Fertitta.

    Cheers,

    Javier.


    • Marked as answer by haydnguy Wednesday, October 26, 2011 5:23 AM
    • Edited by ljestrada Wednesday, October 26, 2011 1:33 PM I'm awake now :-)
    Wednesday, October 26, 2011 5:19 AM

All replies

  • My two cents...

    C++ uses a "Component Extensions" syntax (compiler switch /Cx) that is based on C++/CLI, an ECMA standard that was pushed by Microsoft through Herb Sutter.  The C++/CLI syntax is solid, in my opinion, and you'd be fine in reading some of the C++/CLI documentation or a book such as C++/CLI in Action or one of the APress books.

    Saying that, the differences are minimal--one I can remember from the BUILD sessions by Herb Sutter is the gcnew versus the ref new to initialize a reference class.  Notice that although recycling the syntax, the "hat" notation has a different meaning in WinRT than in the CLR.  In WinRT you'll always be referring to a WinRT compatible type which is not a managed type in the sense of "it is not garbage collected."  The C++ /Cx syntax always produces native code (again, native code does not mean portable code :-) and it is syntactic sugar over the WinRT.  You could always access the lower level of the WinRT via COM (as in COM "Reloaded") and the WRL.

    Finally, to answer your question, I would consider the syntax as finalized--many benefits by recycling the C++/CLI syntax and integrating it with the WinRT.

    Since you come from native code, your mileage will vary, depending on the UI frameworks you've worked with.  I'd recommend downloading the samples after installing the Windows 8 Developer Preview with Tools and Apps (x64), since the other version (Windows 8 Developer Preview with Apps + standalone version of Visual Studio 11 Dev Preview) won't run the Metro style apps--even though it has the templates, the compilation fails.  Perhaps you'll be able to install it and make it run, but I and other developers have been bitten by this "mirage".

    Summarizing:

    A good book on XAML.  All the books out there are about WPF and you learn XAML by learning WPF, but the concepts port to Metro. My recommendation is to look at WPF 4 Unleashed.  This book contains the latest updates to XAML (excluding what changed in Visual Studio 11) and it is a great reference for XAML.  The XAML portion, concepts, data binding, routed events, etc., is reusable in Metro, and several if not most of the WPF concepts are in Metro.

    A good book on C++/CLI to extract the syntax.  Manning's C++/CLI in action is an easy read.  The sections that will not be applicable are the ones where you interface with .NET.  now the interfacing is with WinRT. You can find other, simpler references, and if you're familiar with C#, several of the concepts have been adopted in C++/Cx verbatim (e.g., sealed keyword).  

    If you want to dive into COM to do lower level programming, be my guest.  Albeit some books may be applicable for COM and ATL (using the COM smart pointers, wrappers around enumerations, collections, lifetime of COM objects, factories, apartments, I think you'd be better off with the documentation and the forums for now, but if you must, check Don Box's classic Essential COM and ATL Internals by Chris Sells, Brent Rector, Chris Tavares and Kirk Fertitta.

    Cheers,

    Javier.


    • Marked as answer by haydnguy Wednesday, October 26, 2011 5:23 AM
    • Edited by ljestrada Wednesday, October 26, 2011 1:33 PM I'm awake now :-)
    Wednesday, October 26, 2011 5:19 AM
  • Check out http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-2-C-at-BUILD-Windows-Runtime-LibraryWRL-Meet-Tarek-and-Sridhar  where Sridhar, the designer of WRL, does an excellent white-boarding of how native C++ WRL will work. And Nishant Sivakumar  in http://www.codeproject.com/KB/cpp/WinRTVisualCppIntro.aspx explains how WRL is analogous to what ATL did for MFC. In short, WRL eliminates the need for C++/Cx.


    RT
    unless, of course, you are a C# developer and don't mind the C#-like WinRT extensions.
    • Edited by rtischer8277 Thursday, October 27, 2011 3:21 PM clarification
    Thursday, October 27, 2011 3:17 PM

  •   .ExternalClass .ecxhmmessage P {padding:0px;} .ExternalClass body.ecxhmmessage {font-size:10pt;font-family:Tahoma;}
    Thank you for letting me know about that clip. Curiously, I just happened to be watching the 3rd clip in that series when your email came to me. I will definitely watch #2 as soon as I get through with the current one. Bob

    Thursday, October 27, 2011 3:23 PM