C++/WinRT is designed to give C++ developers uncompromising performance as well as amazing productivity. Come and learn how to make effective use of C++ for the most demanding projects, whether it’s a system component, desktop or console app, or UWP app. In this session, we’ll also walk you through our early support for creating a XAML application in standard C++ and provide tips and guidance on how to move your C++/CX code to use standard C++ with C++/WinRT.
4. The Modern class-based, Object-oriented Windows API
Plus metadata about the classes/members
Plus language projections for natural and familiar use
• C++, C#, JavaScript, others
5.
6. Use any Windows Runtime class as if it were a standard C++ class
Implement a Windows Runtime class using standard C++
Create XAML applications using standard C++ (Preview)
7.
8. Uri "http://aka.ms/cppwinrt" // URI to fetch
HttpClient // Class that does the fetching
auto // Make async call & wait
// Display the page
9. // Uri uri(L"http://aka.ms/cppwinrt");
ComPtr IUriRuntimeClassFactory
THROW_IF_FAILED
ComPtr IUriRuntimeClass
THROW_IF_FAILED
"http://aka.ms/cppwinrt"
For this statement
You must write this code
26. Build
Class description Skeletal implementations
• Generated FilessourcesPhoto.h
• Generated FilessourcesPhoto.cpp
Complete base class Metadata file
• Photo.g.h Photo.winmd
Copy skeletons to project folder
Include in project
Photo.idl
27. namespace
delegate void Boolean // delegate type for event
runtimeclass Photo Windows.UI.Xaml.Data.INotifyPropertyChanged // Interface
// Constructors
Windows.Storage.StorageFile
String get // Read-only property
Single // Read-write property
Windows.Foundation.IAsyncAction // (Async) Method
event RecognitionHandler // event
40. Brevity please
C++ exception handling
ISO C++17 standard
External references
Add /await for C++ coroutine support
41. #include <stdio.h>
#include <winrt/Windows.Foundation.h>
using namespace winrt;
int main()
{
init_apartment();
Windows::Foundation::Uri uri(L"https://microsoft.com/build");
printf("Welcome to %ls!n", uri.Path().c_str());
}
Where does
this come from?
92. IObservableVector<int> v = ...
event_token token = v.VectorChanged([](auto&&, auto&&)
{
printf("Changedn");
});
v.Append(123);
v.VectorChanged(token);
v.Append(234);
64-bit token
Manually revoke handler
Invoke handler
Handler is not called
93. IObservableVector<int> v = ...
auto revoker = v.VectorChanged(auto_revoke, [](auto&&, auto&&)
{
printf("Changedn");
});
v.Append(123);
revoker.revoke();
Create auto-revoker
Includes weak reference to event source
Revoke handler if event source still exists
Destructor also calls revoke
97. event<delegate<std::string, int, float>> changed;
changed.add([](std::string const& a, int b, float c)
{
printf("%s %d %.2fn", a.c_str(), b, c);
});
changed("Hello", 123, .456f);
changed("World", 456, .789f);
delegate<T…>
Non-WinRT types are fine
Doesn’t provide an ABI
98. Ask on stackoverflow using tag [c++-winrt]
https://aka.ms/cppwinrt/stackoverflow