Skip to content

Callback function passed to EnumFontFamiliesExW uses wrong signature #889

@beevvy

Description

@beevvy

Example callback function used with EnumFontFamiliesExW:

int CALLBACK FontEnumForV2Console(ENUMLOGFONT *pelf, NEWTEXTMETRIC *pntm, int nFontType, LPARAM lParam);

But FONTENUMPROC as expected by EnumFontFamiliesExW is defined as follows (SDK 10.0.18362.0):

typedef int (CALLBACK* OLDFONTENUMPROCW)(CONST LOGFONTW *, CONST TEXTMETRICW *, DWORD, LPARAM);

In practice, the differing argument types are representation-compatible anyway, so it works fine, but it does require a cast on the function pointer. It was suggested in #871 to get this sorted out.

Affected files:

>git grep FONTENUMPROC
src/propsheet/misc.cpp:    EnumFontFamiliesEx(hDC, &LogFont, (FONTENUMPROC)((ShouldAllowAllMonoTTFonts()) ? FontEnumForV2Console : FontEnum), (LPARAM)&fed, 0);
src/renderer/gdi/tool/main.cpp:    EnumFontFamiliesExW( hDC, &lf, (FONTENUMPROC)EnumFontFamiliesExProc, 0, 0 );
src/tools/fontlist/main.cpp:    EnumFontFamiliesExW(hdc.get(), &LogFont, (FONTENUMPROC)FontEnumForV2Console, (LPARAM)hdc.get(), 0);

BTW, src/renderer/gdi/tool/main.cpp is not included in any project in the solution, preventing it to be scanned by an IDE. Is that intentional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CodeHealthIssues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc.Help WantedWe encourage anyone to jump in on these.Issue-BugIt either shouldn't be doing this or needs an investigation.Product-ConhostFor issues in the Console codebase

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions