Using the Windows 8 Runtime from C++

2,369 views

Published on

More info on http://www.techdays.be

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,369
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
35
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • PDC-3
  • Using the Windows 8 Runtime from C++

    1. 1. Metro style apps
    2. 2. View Metro style Apps Desktop Apps XAML HTML / CSSController C C# JavaScript Model HTML C C# C++ VB (Chakra) JavaScrip t C++ VB WinRT APIs System Services Communication Graphics & Devices & & Data Media Printing Application Model Internet .NET Explorer Win32 / SL Core Windows Core OS Services
    3. 3. The Sweet Spot for C++… Power, Performance and Portability.
    4. 4. XAML
    5. 5. Demo
    6. 6. Language Basics
    7. 7. 1. Person^ p = nullptr;2. {3. Person^ newP = ref new Person(); // refcount = 14. newP->Name = “John”; // refcount = 15. p = newP; // refcount = 26. } // refcount = 17. p = nullptr; // refcount = 0; ~Person()
    8. 8. Key Bindings Feature Summary1. Data Types ref class Reference type value class Value type interface class Interface property Property with get/set event “Delegate property” with add/remove/raise delegate Type-safe function pointer generic Type-safe generics2. Allocation ref new Reference-counted allocation3. Pointer & ^ Strong pointer (“hat” or “handle”)Reference % Strong reference
    9. 9. More Language
    10. 10. 1. delegate void CarouselInitDoneHandler(IUIAnimationVariable^ rotation);2. void CarouselAnimation::Initialize(double angle, CarouselInitDoneHandler^ callback) {3. // Create Animation Manager4. using namespace Engine::Graphics;5. UIAnimationManager animationManager;6. // Create rotation animation variable7. IUIAnimationVariable^ rotation = animationManager.CreateAnimationVariable(angle);8. // Set the event handler for the story board9. rotation->GetCurrentStoryBoard()->SetStoryBoardEventHandler(10. ref new CarouselStoryBoardHandler(this, CarouselAnimation::StoryBoard)11. );12. // Invoke the callback when done13. callback(rotation);14. }
    11. 11. public ref class Person { public: Person(String^ name, String^ email); void Greet(Person^ other); internal: ~Person(); void SetPassword(const std::wstring& passwd);};Person^ p = ref new Person(“John Surname”);p->Greet(ref new Person(“Jim Surname”);
    12. 12. public interface class IAnimal { public interface class IFeline : void Play(); IAnimal {}; void Scratch(); };IAnimal^ animal = ref new Cat(); ref class Cat : IFeline {animal->Play(); public: virtual void Play(); virtual void Scratch(); };
    13. 13. public ref class DatabaseConnection { public: ~ DatabaseConnection();};{ DatabaseConnection db(); db.SetName( “Employees”); // … // … lots of queries, updates, etc. … // …} // ~DatabaseConnection()
    14. 14. public: property String^ Name;public: property Person^ Sibling { Person^ get() { InitSiblings(); return _sibling; } void set(Person^ value) { _sibling = value; NotifySibling(); } }private: Person^ _sibling; Person^ p = ref new Person(“John”); p->Sibling = ref new Person(p->Name);
    15. 15. public delegate void PropertyChanged( String^ propName, String^ propValue ); auto p = ref new PropertyChanged( [](String^ pn, String^ pv) { cout << pn << ” = “ << pv; } ); auto p = ref new PropertyChanged( UIPropertyChanged ); auto p = ref new PropertyChanged( this, MainPage::OnPropertyChanged ); p( “Visible”, false );
    16. 16. public: event PropertyChanged^ OnPropertyChanged;public: event PropertyChanged^ OnNetworkChanged { EventRegistrationToken add(PropertyChanged^); void remove(EventRegistrationToken t); void raise(String^, String^);}person->OnPropertyChanged += propertyChangedDelegate;auto token = person->OnPropertyChanged::add(propertyChangedDelegate); person->OnPropertyChanged -= token; person->OnPropertyChanged::remove(token);
    17. 17. HRESULT Exception E_OUTOFMEMORY OutOfMemoryException E_INVALIDARG InvalidArgumentException E_NOINTERFACE InvalidCastException E_POINTER NullReferenceException E_NOTIMPL NotImplementedException E_ACCESSDENIED AccessDeniedExceptionthrow ref new InvalidArgumentException(); E_FAIL FailureExceptionthrow ref new COMException(E_*); E_BOUNDS OutOfBoundsException E_CHANGED_STATE ChangedStateException REGDB_E_CLASSNOTREG ClassNotRegisteredExceptiontry { … } catch (OutOfMemoryException^ ex) E_DISCONNECTED { … } E_ABORT DisconnectedException OperationCanceledException ex->HResult• catch (Platform::Exception^)
    18. 18. generic<typename T, typename U> ref class PairStringUri:public interface class IPair { IPair<String^, Uri^> { property T First; public: property U Second; property String^ First;}; property Uri^ Second; };IPair<String^, Uri^>^ uri = GetUri();auto first = uri->First; // type is String^auto second = uri->Second; // type is Uri^
    19. 19. template<typename T, typename U>ref class Pair: IPair<T, U>{public: property T First; property U Second; Pair(T first, U second) { First = first; Second = second; }};IPair<String^, Uri^>^ pair = ref new Pair<String^, Uri^>( “//BUILD/”, ref new Uri(“http://www.buildwindows.com”));
    20. 20. #using <Company.Component.winmd> public
    21. 21. private partial ref class MainPage: UserControl, IComponentConnector{public: void InitializeComponent(); void Connect() { btn1->Click += ref new EventHandler(this, &MainPage::Button_Click); }};ref class MainPage{public: MainPage() { InitializeComponent(); } void Button_Click(Object^ sender, RoutedEventArgs^ e);};
    22. 22. Libraries
    23. 23. using namespace Platform; Vector<String^>^ items = ref new Vector<String^>(); items->Append(“Hello”);• Returning a read-only view of the vector IVectorView<String^>^ GetItems () { return items->GetView(); } items->VectorChanged += ref new VectorChangedEventHandler<String^> (this, &MyClass::VectorChanged);
    24. 24. using namespace Platform;Map<String^, Uri^> favorites = ref new Map<String^, Uri^>();favorites->Insert(“MSDN”, ref new Uri(“http://msdn.com”));if (favorites->HasKey(“MSDN”)) favorites->Remove(“MSDN”);
    25. 25. Begin()/End() std::vector<int> v; begin() end() v.push_back(10); auto items = ref new Vector<int>(v);IVector<int>^ v = GetItems();int sum = 0; Vector<int>^ items = …;std::for_each( begin(v), end(v), std::vector<int> v = to_vector(items); [&sum](int element) { sum += element; } );
    26. 26. Building your first Windows Metro style app Roadmap for creating Metro style apps Tour of the IDE• XAML designer C++ Reference for Windows Runtime Windows Runtime Components in C++ Asynchronous Programming in C++ Using PPL
    27. 27. (Since 10th of January 2012) http://BeCPP.org/ Aim? quarterly meetings Audience? free for everyone Where? At Microsoft offices in Zaventem or at sponsor company locations (we’re still looking for hosts / sponsors!) Announcements? subscribe to our blog to stay up-to-date Questions? BeCPP@BeCPP.org or visit the TechDays MEET Corner during breaks
    28. 28. MICROSOFTC++ 2012PARTICIPATE IN C++ MICROSOFT DEVELOPER DIVISIONDEVELOPMENT USER DESIGN RESEARCHRESEARCH SIGN UP ONLINE AT http://bit.ly/cppdeveloper
    29. 29. http://aka.ms/mbl-win8 http://aka.ms/mbl-win8/build http://aka.ms/mbl-win8/devprev http://aka.ms/mbl-win8/store

    ×