GDI+ PrivateFontCollection::AddMemoryFont failed to load fonts

RL Chen 230 Reputation points
2024-05-30T01:03:33.4266667+00:00

GDI+ PrivateFontCollection::AddMemoryFont fails to load fonts and returns a status of InvalidParameter = 2. I made sure that my resources were correct as I also saved them locally, but the ttf fonts are correct. What is the problem please?

My code and simplified project that shows the problem: OneDrive

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,492 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,608 questions
{count} votes

Accepted answer
  1. Viorel 114K Reputation points
    2024-05-30T05:40:11.72+00:00

    Try to use the GDI+ variables after initialisation of GDI+ engine. For example:

    // PrivateFontCollection fontCollection; <-- MOVED
    
    int main()
    {
    	GdiplusStartupInput gdiplusStartupInput;
    	ULONG_PTR gdiplusToken;
    	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    
        PrivateFontCollection fontCollection;
        . . .
    

    To use global variables:

    PrivateFontCollection* fontCollection;
    
    int main()
    {
    	GdiplusStartupInput gdiplusStartupInput;
    	ULONG_PTR gdiplusToken;
    	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    
        fontCollection = new PrivateFontCollection;
        . . .
    

0 additional answers

Sort by: Most helpful