D2D DWrite encountered error 0x88985001 while loading a custom font. Repeated debugging attempts failed to pinpoint the issue. Please help me.

RL Chen 260 Reputation points
2025-08-27T06:42:25.4966667+00:00

I am attempting to add a TTC font to an IDWriteFontCollection and have chosen to register a custom loader using RegisterFontCollectionLoader(collectionLoader);. The font file is located within a resource file (.rc).

devenv_Ysb97BuaID

The font file format is .ttf, but DWrite recognizes it as a TTC font (hence the design in my code to handle this), and this TTC font contains only one font face (meaning a single font).

I simplified and created a standalone test project containing extensive debugging output, but I still can't pinpoint the issue. When loaded directly from its actual local path, this font file loads correctly (indicating the font itself is not the problem).

enter image description here

I have placed my test sample in cloud storage. It contains the entire solution project (code, fonts, etc.), making it convenient for you to download and test.

OneDrive


Below is a portion of my code (as it's too lengthy), where I've included only an example of the loading process.

INT numFound = 0;
HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(101), L"TTF");
HGLOBAL hMem = LoadResource(NULL, hRes);
void* pLock = LockResource(hMem);
DWORD dwSize = SizeofResource(NULL, hRes);

BYTE* alignedData = static_cast<BYTE*>(_aligned_malloc(dwSize, 16));
if (!alignedData) cout << "alignedData malloc failed!" << endl;
memcpy(alignedData, pLock, dwSize);

auto fileLoader = new IdtFontFileLoader();
auto collectionLoader = new IdtFontCollectionLoader(D2DTextFactory, fileLoader);

D2DTextFactory->RegisterFontFileLoader(fileLoader);
D2DTextFactory->RegisterFontCollectionLoader(collectionLoader);

IDWriteFontCollection* tempFontCollection = nullptr;
HRESULT hr = D2DTextFactory->CreateCustomFontCollection(collectionLoader, alignedData, dwSize, &tempFontCollection);

Meanwhile, DWrite can correctly identify the font's properties but fails to load the font itself. My previous code successfully loaded TTF (single-font-face fonts), but I later made modifications to this TTC font (which suggests my code issue shouldn't be too significant).

IDWriteFontFile* fontFile = nullptr;
hr = D2DTextFactory->CreateCustomFontFileReference(
	pLock, dwSize,
	fileLoader,
	&fontFile
);

BOOL    supported = FALSE;
DWRITE_FONT_FILE_TYPE   fileType;
DWRITE_FONT_FACE_TYPE   faceType;
UINT32  faceCount = 0;

fontFile->Analyze(
	&supported,
	&fileType,
	&faceType,
	&faceCount
);

printf(
	"HarmonyOS Sans Analyze: supported=%d fileType=%u faceType=%u faceCount=%u\n",
	supported, fileType, faceType, faceCount
);

Code output obtained

IdtFontFileStream::GetFileSize CALLED
IdtFontFileStream::ReadFileFragment CALLED: Offset = 0, Size = 117
IdtFontFileStream::ReadFileFragment CALLED: Offset = 0, Size = 7
IdtFontFileStream::ReadFileFragment CALLED: Offset = 0, Size = 16
HarmonyOS Sans Analyze: supported=1 fileType=2 faceType=1 faceCount=1

I've been working on this problem for six hours now. Please help me out. I'd be extremely grateful!

Windows development | Windows API - Win32
{count} vote

1 answer

Sort by: Most helpful
  1. RL Chen 260 Reputation points
    2025-12-04T03:38:06.6966667+00:00

    Following the official example, I rewrote this code and have resolved the issue.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.