Problems calling CreateFontIndirect

P

Per Rasmussen

I need to call the function CreateFontIndirect. I have made my header like
this:

private class LOGFONT
{
private int lfHeight;
private int lfWidth;
private int lfEscapement;
private int lfOrientation;
private int lfWeight;
private byte lfItalic;
private byte lfUnderline;
private byte lfStrikeOut;
private byte lfCharSet;
private byte lfOutPrecision;
private byte lfClipPrecision;
private byte lfQuality;
private byte lfPitchAndFamily;
private char[] lfFaceName;
}

[DllImport("coredll.dll")]
private static extern IntPtr CreateFontIndirect(ref LOGFONT lplf);

But when I call the function like this:

LOGFONT lf = new LOGFONT;
... // Setting lf
hfont = CreateFontIndirect(ref lf);

I get a NotSupportedExeption. How should I do it?
 
P

Peter Foot [MVP]

The problem is with .NETCF v1.0 you can't marshal an array with a nested
character array. The workaround is to store your logfont as a single byte
array and then use the BitConverter to get and set individual members within
the structure. For examples of this technique have a browse through the
OpenNETCF source in the vault - http://vault.netcf.tv (username guest,
password guest).

Peter
 
P

Per Rasmussen

Thanks, but where in this vault should I look?

Peter Foot said:
The problem is with .NETCF v1.0 you can't marshal an array with a nested
character array. The workaround is to store your logfont as a single byte
array and then use the BitConverter to get and set individual members
within the structure. For examples of this technique have a browse through
the OpenNETCF source in the vault - http://vault.netcf.tv (username guest,
password guest).

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://blog.opennetcf.org/pfoot/

Per Rasmussen said:
I need to call the function CreateFontIndirect. I have made my header like
this:

private class LOGFONT
{
private int lfHeight;
private int lfWidth;
private int lfEscapement;
private int lfOrientation;
private int lfWeight;
private byte lfItalic;
private byte lfUnderline;
private byte lfStrikeOut;
private byte lfCharSet;
private byte lfOutPrecision;
private byte lfClipPrecision;
private byte lfQuality;
private byte lfPitchAndFamily;
private char[] lfFaceName;
}

[DllImport("coredll.dll")]
private static extern IntPtr CreateFontIndirect(ref LOGFONT lplf);

But when I call the function like this:

LOGFONT lf = new LOGFONT;
... // Setting lf
hfont = CreateFontIndirect(ref lf);

I get a NotSupportedExeption. How should I do it?
 
C

Chris Tacke, eMVP

The OpenNETCF.Drawing.FontEx class comes to mind....

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


Per Rasmussen said:
Thanks, but where in this vault should I look?

Peter Foot said:
The problem is with .NETCF v1.0 you can't marshal an array with a nested
character array. The workaround is to store your logfont as a single byte
array and then use the BitConverter to get and set individual members
within the structure. For examples of this technique have a browse
through the OpenNETCF source in the vault - http://vault.netcf.tv
(username guest, password guest).

Peter

--
Peter Foot
Windows Embedded MVP
http://www.inthehand.com | http://blog.opennetcf.org/pfoot/

Per Rasmussen said:
I need to call the function CreateFontIndirect. I have made my header
like this:

private class LOGFONT
{
private int lfHeight;
private int lfWidth;
private int lfEscapement;
private int lfOrientation;
private int lfWeight;
private byte lfItalic;
private byte lfUnderline;
private byte lfStrikeOut;
private byte lfCharSet;
private byte lfOutPrecision;
private byte lfClipPrecision;
private byte lfQuality;
private byte lfPitchAndFamily;
private char[] lfFaceName;
}

[DllImport("coredll.dll")]
private static extern IntPtr CreateFontIndirect(ref LOGFONT lplf);

But when I call the function like this:

LOGFONT lf = new LOGFONT;
... // Setting lf
hfont = CreateFontIndirect(ref lf);

I get a NotSupportedExeption. How should I do it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top