0

I'm facing a problem which I'm killing myself over. I have the following code:

ComPtr<IDWriteFactory> factory;
DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), factory.GetAddressOf();
ComPtr<IDWriteTextFormat> textFormat;
factory->CreateTextFormat(L"Arial", nullptr, DWRITE_FONT_WEIGHT_NORMAL,
    DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 20.0f, nullptr,
    textFormat.GetAddressOf());

After the last line textFormat points to null. CreateTextFormat() returns the value E_INVALIDARG. I definitely have Arial installed, the two nullptr parameters are allowed according to MSDN, so I don't see what can be invalid. Can anyone shed some light on this?

  • Your supplying `nullptr` for local name is questionable, did you try "en-us" instead? – Roman R. Feb 08 '15 at 18:59
  • textFormat appears to be something other than null now, so it's probably fixed. It just seems odd how an MSDN example uses null for the locale name... –  Feb 08 '15 at 19:06
  • 2
    Does it work with an empty string `L""` and not `nullptr`? A comment on [this page](https://msdn.microsoft.com/en-us/library/windows/desktop/dd368203.aspx) claims so. – CodeAngry Feb 09 '15 at 10:07

1 Answers1

2

Like CodeAngry said, the language tag and familyName cannot be null (In_z rather than In_opt_z). Either may be empty though "", in which case no particular language is used and default fallback fonts are chosen.

Dwayne Robinson
  • 2,034
  • 1
  • 24
  • 39