Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
addfontmemresourceex (gdi32)
Adds the font resource from a memory image to the system.

C# Signature:

[DllImport("gdi32.dll", ExactSpelling=true)]

private static extern IntPtr AddFontMemResourceEx(byte[] pbFont, int cbFont, IntPtr pdv, out uint pcFonts);

User-Defined Types:



When the function succeeds, the caller of this function can free the memory pointed to by pbFont because the system has made its own copy of the memory. To remove the fonts that were installed, call RemoveFontMemResourceEx. However, when the process goes away, the system will unload the fonts even if the process did not call RemoveFontMemResourceEx.

Tips & Tricks:

Calling this API is required when working with PrivateFontCollection and AddMemoryFont, or you won't get it working.

Sample Code:

PrivateFontCollection privateFontCollection = new PrivateFontCollection();

byte[] fontdata = MyAssembly.Properties.Resources.ZeroThreesFont; // Getting Zero Threes embedded font from Resources (.NET 2.0)

IntPtr ptrFont = Marshal.AllocCoTaskMem(fontdata.Length);

uint cFonts;

AddFontMemResourceEx(fontdata, fontdata.Length, IntPtr.Zero, out cFonts);

Marshal.Copy(fontdata, 0, ptrFont, fontdata.Length);

privateFontCollection.AddMemoryFont(ptrFont, fontdata.Length);


Alternative Managed API:

Do you know one? Please contribute it!


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version