[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
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=32)]
public string lfFaceName;
}
TODO
None.
See this MSDN reference: Default Marshaling for Strings
Please add some!
Please add some!
The .NET Framework class Font, has a method, Font::FromLogfont that takes an Object reference as it's method parameter. You must define a managed LOGFONT class using the same format as the C# signature above. When using the StructLayout attribute on the class definition, you must set the CharSet property to Auto (the default is Ansi, which will not work correctly). The only difficulty encountered is passing the string value (the designated Font Face Name) to the FromLogfont method; apparently, this must have the MarshalAs(UnmanagedType::ByValTStr enum value) for the method to work correctly. Then, when instantiating in your managed application, you must cast the LOGFONT class (with approprite member values assigned) to a System::Object for the function to work without generating a runtime exception.