Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


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

AddFontMemResourceEx (gdi32)
 
.
Summary
Adds the font resource from a memory image to the system.

C# Signature:

[DllImport("gdi32.dll")]
static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont,
   IntPtr pdv, [In] ref uint pcFonts);

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

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

User-Defined Types:

None.

Notes:

None.

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:

Please add some!

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

Sample Code:

Please add some!

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);

Alternative Managed API:

Do you know one? Please contribute it!

uint cFonts;

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

Documentation

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

privateFontCollection.AddMemoryFont(ptrFont, fontdata.Length);

Marshal.FreeCoTaskMem(ptrFont);

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

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 PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions