I don't see your attached code, but this test works for me :
using (Graphics gr = Graphics.FromHwnd(IntPtr.Zero))
{
IntPtr hDC = gr.GetHdc();
LOGFONT lf = new LOGFONT();
lf.lfCharSet = DEFAULT_CHARSET;
IntPtr pLogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf));
Marshal.StructureToPtr(lf, pLogFont, true);
EnumFontFamiliesEx(hDC, pLogFont, EnumFontFamExProc, IntPtr.Zero, 0);
Marshal.FreeHGlobal(pLogFont);
gr.ReleaseHdc(hDC);
}
public int EnumFontFamExProc(ref ENUMLOGFONTEX lpelfe, ref NEWTEXTMETRICEX lpntme, uint FontType, IntPtr lParam)
{
// code...
return 1;
}
with :
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int EnumFontFamiliesEx(IntPtr hdc, [In] IntPtr pLogfont, FONTENUMPROC lpEnumFontFamExProc, IntPtr lParam, uint dwFlags);
public delegate int FONTENUMPROC(ref ENUMLOGFONTEX lpelfe, ref NEWTEXTMETRICEX lpntme, uint FontType, IntPtr lParam);
public const int ANSI_CHARSET = 0;
public const int DEFAULT_CHARSET = 1;
public const int SYMBOL_CHARSET = 2;
public const int LF_FACESIZE = 32;
public const int LF_FULLFACESIZE = 64;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ENUMLOGFONTEX
{
public LOGFONT elfLogFont;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FULLFACESIZE)]
public string elfFullName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FACESIZE)]
public string elfStyle;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FACESIZE)]
public string elfScript;
public override string ToString()
{
return elfFullName;
}
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NEWTEXTMETRIC
{
public int tmHeight;
public int tmAscent;
public int tmDescent;
public int tmInternalLeading;
public int tmExternalLeading;
public int tmAveCharWidth;
public int tmMaxCharWidth;
public int tmWeight;
public int tmOverhang;
public int tmDigitizedAspectX;
public int tmDigitizedAspectY;
public char tmFirstChar;
public char tmLastChar;
public char tmDefaultChar;
public char tmBreakChar;
public byte tmItalic;
public byte tmUnderlined;
public byte tmStruckOut;
public byte tmPitchAndFamily;
public byte tmCharSet;
int ntmFlags;
int ntmSizeEM;
int ntmCellHeight;
int ntmAvgWidth;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct FONTSIGNATURE
{
[MarshalAs(UnmanagedType.ByValArray)]
int[] fsUsb;
[MarshalAs(UnmanagedType.ByValArray)]
int[] fsCsb;
}
public struct NEWTEXTMETRICEX
{
NEWTEXTMETRIC ntmTm;
FONTSIGNATURE ntmFontSig;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision;
public byte lfQuality;
public byte lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FACESIZE)]
public string lfFaceName;
}