[DllImport("gdi32.dll")]
static extern uint GetOutlineTextMetrics(IntPtr hdc, uint cbData, IntPtr ptrZero);
Since otmpFamilyName, otmpFaceName, otmpStyleName, otmpFullName are actually offsets into the structure from the beginning of the structure you need double call GetOutlineTextMetrics.
First call returns needed buffer size the second fills buffer by actual data.
private static void GetOutlineMetrics(IntPtr hdc)
{
uint cbBuffer = GetOutlineTextMetrics(hdc, 0, IntPtr.Zero);
if (cbBuffer == 0)
return;
IntPtr buffer = Marshal.AllocHGlobal((int)cbBuffer);
try
{
if (GetOutlineTextMetrics(hdc, cbBuffer, buffer) != 0)
{
OUTLINETEXTMETRIC otm = new OUTLINETEXTMETRIC();
otm = (OUTLINETEXTMETRIC)Marshal.PtrToStructure(buffer, typeof(OUTLINETEXTMETRIC));
string otmpFamilyName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpFamilyName));
string otmpFaceName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpFaceName));;
string otmpStyleName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpStyleName));;
string otmpFullName = Marshal.PtrToStringAnsi(new IntPtr((int)buffer + otm.otmpFullName));;
}
}
finally
{
Marshal.FreeHGlobal(buffer);
}
}
Do you know one? Please contribute it!