microsoft consumer channels and central marketing group
DESCRIPTION
Agenda WRL Overview WRL Classes Consuming WinRT Project template Demo 4/26/2017 Agenda WRL Overview WRL Classes Consuming WinRT Mentions these are not in order of importance. Hint of Windows on ARM, but don’t add it as a bullet. Project template Demo © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.TRANSCRIPT
WRLSridhar Madhugiri, Software Design EngineerLukasz Chodorski, Software Design EngineerMicrosoft Corporation
WRLTemplate based implementationConsume and Author WinRT objectsException FreeWorks at ABI levelDeveloped specifically for WinRT
Why use WRLPorting COM components to MetroNo exceptions requirementInterop with Com No C++ extensions requirementFine grained control
Winrt ConceptsWinRT ObjectReference countedImplements IInspectableInstantiated through factoryWeakReference support
DelegateCallbackInterface with methodDelegate instance is WinRT object
EventDelegate used as Event callbackServer advertises eventsClient creates delegate and registers it to receive events
MiscReference count managementAsynchronous operations
WRL ClassesWinRT ObjectRuntimeClassInspectableClassActivatableClassActivationFactory
DelegateCallback
EventEventSourceCallback
MiscComPtr, WeakPtrAsyncBaseAnd many more
ComPtr, HStringComPtr<IActivationFactory> activationFactory;HRESULT hr = GetActivationFactory(
HString::MakeReference(RuntimeClass_Windows_Foundation_Uri).Get(), &activationFactory
);// Error handling
ComPtr<IUriRuntimeClassFactory> uriActivationFactory;hr = activationFactory.As(&uriActivationFactory);// Error handling
ComPtr<IUriRuntimeClass> uri;
hr = uriActivationFactory->CreateUri(HString::MakeReference(L"http://www.microsoft.com").Get(),&uri
);// Error handling
Wrappers::HString domainName;hr = uri->get_Domain(domainName.GetAddressOf());// Error handling
DelegateComPtr<IThreadPoolTimerStatics> timerFactory; HRESULT hr = GetActivationFactory(
Wrappers::HString::MakeReference(RuntimeClass_Windows_System_Threading_ThreadPoolTimer).Get(), &timerFactory
); // Error handling TimeSpan delay;delay.Duration = 200; ComPtr<IThreadPoolTimer> timer;hr = timerFactory->CreateTimer(
Callback<ITimerElapsedHandler>([](IThreadPoolTimer* timer) -> HRESULT {
// Perform some action in separate thread return S_OK;
}).Get(), delay, &timer
);
Available in Online template gallerySelect Online/Templates/C++/WRL Class Library in New project dialogDoes not work with Beta
Template generated filesProject file with correct settingsIDL file with one interface and one runtimeclassSource files that implement the interface and runtime classBroiler plate code to implement standard exports
Project template
Project filesProject settingsPreprocessor Define• WINAPI_FAMILY=WINAPI_PARTITION_AP
PMIDL setting to generate WinMDCustom build step for mdmerge
IDLnamespaceruntimeclass, interfaceexclusiveto, activatable
Module.cppBroilerplate codeWires exports to WRL activation infrastructure
WRLClassLibrary1.cppRuntimeClass• Template parameters - interfaces for
Object• Implements- AddRef, Release, QI, GetIids• WeakReference support
InspectableClass• Implements – GetRuntimeclassName,
GetTrustLevel
ActivatableClass• Associates default Activation factory with
class• Wires factory to WRL activation
infrastructure
IDLDelegate definition – keyword delegate• MIDL creates an interface with method that matches delegate signatureAdd eventadd and eventremove methods to interface• Name of both methods should be same• Fixed signature
CPPEventSource templated on delegate interface as member of classAdd methods corresponding to eventadd and eventremove methods in interface• Delegate represented by its interface name• eventadd function has add_ prefix and eventremove has remove_ prefix• In the implementation of add/remove call Add/Remove on EventSource• Invoke event by calling InvokeAll on EventSource
Add Event
IDLDefine constructor factory interface• Add one or more constructor methods, exclusiveto attribute• Out/retval parameter type has to match type specified with exclusivetoSpecify factory interface as parameter to activatable attribute on runtimeclass
CPP
Add Custom Constructor
Implement RuntimeClassInitialize• Two phase construction• Default constructor cannot fail• Parameters same as the ones on
constructor interface method
Add factory class• Template on Constructor interface• Implement constructor interface
methods• MakeAndInitialize
• instantiates class & calls RuntimeClassInitialize
Use ActivitableClassWithFactory• Similar to ActivitableClass
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.