RemoveFontResourceW function (wingdi.h)

The RemoveFontResource function removes the fonts in the specified file from the system font table.

If the font was added using the AddFontResourceEx function, you must use the RemoveFontResourceEx function.

Syntax

BOOL RemoveFontResourceW(
  [in] LPCWSTR lpFileName
);

Parameters

[in] lpFileName

A pointer to a null-terminated string that names a font resource file.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Remarks

We recommend that if an app adds or removes fonts from the system font table that it notify other windows of the change by sending a WM_FONTCHANGE message to all top-level windows in the system. The app sends this message by calling the SendMessage function with the hwnd parameter set to HWND_BROADCAST.

If there are outstanding references to a font, the associated resource remains loaded until no device context is using it. Furthermore, if the font is listed in the font registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts) and is installed to any location other than the %windir%\fonts\ folder, it may be loaded into other active sessions (including session 0).

When you try to replace an existing font file that contains a font with outstanding references to it, you might get an error that indicates that the original font can't be deleted because it’s in use even after you call RemoveFontResource. If your app requires that the font file be replaced, to reduce the resource count of the original font to zero, call RemoveFontResource in a loop as shown in this example code. If you continue to get errors, this is an indication that the font file remains loaded in other sessions. Make sure the font isn't listed in the font registry and restart the system to ensure the font is unloaded from all sessions.

Note  Apps where the original font file is in use will still be able to access the original file and won't use the new font until the font reloads. Call AddFontResource to reload the font. We recommend that you call AddFontResource the same number of times as the call to RemoveFontResource succeeded as shown in this example code.
 

int i = 0;
while( RemoveFontResource( FontFile ) )
{
    i++;
}

// TODO: Replace font file

while( i-- )
{
    AddFontResource( FontFile );
}

Note

The wingdi.h header defines RemoveFontResource as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header wingdi.h (include Windows.h)
Library Gdi32.lib
DLL Gdi32.dll

See also

AddFontResource

Font and Text Functions

Fonts and Text Overview

RemoveFontResourceEx

SendMessage