May 11th, 2020

Peeking inside WRL weak references

The Windows Runtime C++ Template Library (WRL) also provides a standard implementation of the IWeakReference interface. Here’s what it looks like:

0:000> $ 64-bit version
0:000> dt Microsoft::WRL::Details::WeakReferenceImpl
   +0x000 __VFN_table : Ptr64
   +0x00c refcount_        : Int4B
   +0x010 strongRefCount_  : Int4B
   +0x018 unknown_         : Ptr64 IUnknown

0:000> $ 32-bit version
0:000> dt Microsoft::WRL::Details::WeakReferenceImpl
   +0x000 __VFN_table : Ptr32
   +0x008 refcount_        : Int4B
   +0x00c strongRefCount_  : Int4B
   +0x010 unknown_         : Ptr32 IUnknown

The offsets are different, but the basic idea should look familiar: It’s basically the same as C++/CX weak references. The offsets are different because the WRL control block is made up out of multiple base classes, so you end up with alignment padding.

The members serve the same purpose as they did in C++/CX, so I will defer to earlier discussion.

You can find the implementation of WRL weak references in wrl/implements.h.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

4 comments

Discussion is closed. Login to edit/delete existing comments.

  • Bert Huijben

    I read Int48 but I see 32 bit offsets (with some additional spacing on 64 bit)? I think at least something in the tables is off or needs more explanation.

    • Raymond ChenMicrosoft employee Author

      That’s not Int48. It’s Int4B (letter B). Integer, four bytes. I have no idea why the type is named after its size in bytes rather than it size in bits.

  • cheong00

    This is the first time I see someone defer to something earlier. 😛

    Or maybe it’s something written later but appear earlier on queue.

    • Raymond ChenMicrosoft employee Author

      The English language is weird. There are multiple senses of “defer”. One is “to postpone”. Another is “to yield”.