1 / 23

WRL

WRL. Sridhar Madhugiri, Software Design Engineer Lukasz Chodorski, Software Design Engineer Microsoft Corporation. Agenda. WRL Overview. WRL Classes. Consuming WinRT. Project template. Demo. WRL Overview. WRL. Template based implementation. Consume and Author WinRT objects.

agatha
Download Presentation

WRL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WRL Sridhar Madhugiri, Software Design Engineer Lukasz Chodorski, Software Design Engineer Microsoft Corporation

  2. Agenda WRL Overview WRL Classes Consuming WinRT Project template Demo

  3. WRL Overview

  4. WRL Template based implementation Consume and Author WinRT objects Exception Free Works at ABI level Developed specifically for WinRT

  5. Why use WRL Porting COM components to Metro No exceptions requirement Interop with Com No C++ extensions requirement Fine grained control

  6. WRL Classes

  7. Winrt Concepts WinRT Object Reference counted Implements IInspectable Instantiated through factory WeakReference support Delegate Callback Interface with method Delegate instance is WinRT object Event Delegate used as Event callback Server advertises events Client creates delegate and registers it to receive events Misc Reference count management Asynchronous operations

  8. WRL Classes WinRT Object RuntimeClass InspectableClass ActivatableClass ActivationFactory Delegate Callback Event EventSource Callback Misc ComPtr, WeakPtr AsyncBase And many more

  9. Consuming WinRT

  10. ComPtr, HString ComPtr<IActivationFactory>activationFactory; HRESULThr = 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::HStringdomainName; hr = uri->get_Domain(domainName.GetAddressOf()); // Error handling

  11. Delegate ComPtr<IThreadPoolTimerStatics> timerFactory;    HRESULThr = 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 returnS_OK; } ).Get(), delay, &timer );

  12. WRL Project Template

  13. Project template Available in Online template gallery Select Online/Templates/C++/WRL Class Library in New project dialog Does not work with Beta Template generated files Project file with correct settings IDL file with one interface and one runtimeclass Source files that implement the interface and runtime class Broiler plate code to implement standard exports

  14. demo Default WRL project

  15. Project files Project settings Preprocessor Define WINAPI_FAMILY=WINAPI_PARTITION_APP MIDL setting to generate WinMD Custom build step for mdmerge IDL namespace runtimeclass, interface exclusiveto, activatable Module.cpp Broilerplate code Wires exports to WRL activation infrastructure WRLClassLibrary1.cpp RuntimeClass 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

  16. demo Add method

  17. Add Method IDL Add method to interface CPP Implement method in class __stdcall important

  18. demo Add event

  19. Add Event IDL Delegate definition – keyword delegate MIDL creates an interface with method that matches delegate signature Add eventadd and eventremove methods to interface Name of both methods should be same Fixed signature CPP EventSourcetemplated on delegate interface as member of class Add 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

  20. demo Add non default constructor

  21. Add Custom Constructor IDL Define constructor factory interface Add one or more constructor methods, exclusiveto attribute Out/retval parameter type has to match type specified with exclusiveto Specify factory interface as parameter to activatable attribute on runtimeclass CPP 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

  22. Conclusion Fairly easy to use Exceptions cannot cross ABI boundary Tedious

  23. © 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.

More Related