Click here to Skip to main content
13,149,738 members (55,211 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 3 May 2014

WRL Collection Library Ported to Native C++

, 6 Dec 2015
Rate this:
Please Sign up or sign in to vote.
WRL Collection library ported to native C++


Microsoft includes the entire source for the collection wrappers in collection.h yet they provide the WRL wrappers in the conditional compilation only to support C++/CX. If you want to wrap the existing STL vectors in objects implementing WRL interfaces or wrap WRL vectors in STL vectors, then you need to roll your own library or port Microsoft's like I have done. This can be done by translating all the C++/CX code to C++.


One should be familiar with C++, IDL, basic WRL, the Windows Runtime and C++/CX to be able to manage an entire project in native C++ and be aware of the significant overhead required with the main savings being in size from not having to link with the C++/CX platform wrapper library.

Using the Code

IDL may need to be added to provide custom template specializations while being sure to include the generated header file where you will use the specialization:

    interface Windows.Foundation.Collections.IVector<int>;

The usage is identical to C++/CX except adding the ABI namespace and the usual porting of the Platform namespace objects such as Platform::Object^ to IInspectable* or Platform::String^ to HSTRING. For example, using the hidden VectorIterator is as simple as taking an IVector returned from WRL and doing range enumeration as the begin and end functions are already defined to utilize it:

ABI::Windows::Foundation::Collections::IVector<IInspectable*> vector;
for (auto item : vector) { // process item

Using the Vector class which automatically casts to IVector is similarly easy though only native WinRT types are supported:

Collections_winrt::Vector<HSTRING> vector;

Points of Interest

Although this port was relatively straight-forward, caution should be used as the overhead of using WRL objects is greater than that of the native STL objects. Only use these utilities when interacting with WRL code or objects. Microsoft has put in support for the bindable interfaces too which although can be disabled also required a series of wrapper classes to avoid multiple inheritance conflicts.

The Agile wrapper is translated to WRL to provide proper compatibility for this library.

The library here is contained in the namespace Collections_winrt as opposed to Platform::Collection.

This port supports Visual Studio 2012/2013/2015 and Windows 8/8.1/10/10 v1511 in one library and relatively few changes were made between the versions mostly adding a couple map classes and the use of the new STL initializer_list in constructors.


  • 3rd May, 2014: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Gregory Morse
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionDoesn't build in VS2017 Pin
Member 162182613-Sep-17 11:55
memberMember 162182613-Sep-17 11:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170924.2 | Last Updated 6 Dec 2015
Article Copyright 2014 by Gregory Morse
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid