Windows Template Library

The Windows Template Library, or WTL, is a template-based C++ library developed (but not supported) by Microsoft. It provides features similar to those of MicrosoftFoundationClasses, but in much smaller package. It is available under the CommonPublicLicense at http://wtl.sf.net.

WTL is based on the ActiveTemplateLibrary, which uses UpsideDownInheritance (http://www.apostate.com/programming/atlupsidedown.html) up the wazoo. They are doing it because GUI coding by its nature should be in a dynamic language, and templates are CeePlusPlus's answer to dynamics with compile-time binding; Additionally, using UDI allows them to do away with virtual function tables in many cases, which leads to significantly smaller objects.

For example, to adapt your parent class to you, you expand your parental template with your own type:

 class CMainFrame : 
  public CFrameWindowImpl<CMainFrame>,  
  public CUpdateUI<CMainFrame>,
  public CMessageFilter, 
  public CIdleHandler,
  public IMainFrame,
  public CPrintJobInfo
  {  
Yes, folks, we are using inheritance as a substitute for delegation. That says "My frame CAN (not IS) hold child windows, filter messages, bind to ActiveX, and print".

Now before we purists go reviling MS's architectural decisions (and their effects on thousands of newbies), read the rest of the header file. It's full of implementation function definitions. CPP files are out. This is not abuse of traditional C++ ideals (especially LargeScaleCppSoftwareDesign), it is simply CppHeresy in action. Parallel evolution, huh?

A healthy 3rd-party cottage industry of Web sites and such "support" WTL, and many win32 developers are finding it's their weapon of choice.


CategoryCpp CategoryCppTemplates


EditText of this page (last edited November 17, 2006) or FindPage with title or text search