c++inheritancewinapicomdirectwrite

How to access DirectWrite inherited interfaces in C++?


I am using C++ to work with DirectWrite but I cannot seem to figure out how to use methods that are in inherited interfaces. For example, the " GetUnicodeRanges" method/function in the IDwriteFont1 interface.

The IDWriteFont1 interface/object is not accessed by any other DirectWrite interface/object, including IDWriteFactory - IDWriteFactory7.

The IDWriteFont1 interface inherits from the IDWriteFont interface. I tried various ways of creating a IDWriteFont1 object including the use of DWriteCreateFactory, but that approach seems mainly for creating the various IDWriteFactory objects.

I am able to access IDWriteFont through IDWriteFontCollection through IDWriteFactory via the DWriteCreateFactory function in DWrite.dll.

Can anyone provide direction or example C++ code?


Solution

  • You should be able to do IUnknown::QueryInterface from IDWriteFont interface pointer and get IDWriteFont1 provided that it is available and implemented there in first place of course.

    That is, some pseudo-code:

    IDWriteFont* Font = ...
    assert(Font);
    IDWriteFont1* Font1 = nullptr;
    if(SUCCEEDED(Font->QueryInterface(__uuidof(IDWriteFont1), reinterpret_cast<VOID**>(&Font1))))
    {
      assert(Font1);
      ...
      Font1->GetUnicodeRanges(...)
      ...
    }
    

    The idea behind this is that extensibility updates keep original implemetnation intact and add new functionality by implementing newer version of interfaces on the same objects (font objects in your case). Updates are transparent for older applications that consume APIs using original interfaces and newer apps can discover and consume new functionality by obtaining newer and extended interfaces. This is assumed but documentation sometimes is not exactly clear about how this is supposed to work.