CreateFontIndirect in VB.Net CF

B

Benjamin Lukner

Hi!

I'm trying to use ExtTextOut with WinCE 4.1.
CreateFont is not supported, so I obvously have to use
CreateFontIndirect. But I still have problems with structures under
VB.Net. The following code doesn't work (NotSupportedException).
Does anyone know how to do it right?


<System.Runtime.InteropServices.structlayout _
(Runtime.InteropServices.LayoutKind.Sequential)> _
Private Structure LogFont
Dim nHeight As Int32
Dim nWidth As Int32
Dim nEscapement As Int32
Dim nOrientation As Int32
Dim fnWeight As Int32
Dim fdwItalic As Byte
Dim fdwUnderline As Byte
Dim fdwStrikeOut As Byte
Dim fdwCharSet As Byte
Dim fdwOutputPrecision As Byte
Dim fdwClipPrecision As Byte
Dim fdwQuality As Byte
Dim fdwPitchAndFamily As Byte
<VBFixedString(32)> Dim lpszFace As String
End Structure

Private Declare Function CreateFontIndirect _
Lib "CoreDLL.dll" _
Alias "CreateFontA" ( _
ByVal lplf As LogFont _
) As IntPtr


Dim hObject As IntPtr
Dim uFont As LogFont

With uFont
.nWidth = 10
.nHeight = 20
.nEscapement = 0
.nOrientation = 0
.fnWeight = 0
.fdwItalic = 0
.fdwUnderline = 0
.fdwStrikeOut = 0
.fdwCharSet = DEFAULT_CHARSET
.fdwOutputPrecision = OUT_TT_PRECIS
.fdwClipPrecision = CLIP_DEFAULT_PRECIS
.fdwQuality = ANTIALIASED_QUALITY
.fdwPitchAndFamily = FIXED_PITCH
.lpszFace = "Courier New"
End With

hObject = CreateFontIndirect(uFont)


Kind regards,

Benjamin Lukner
 
B

Benjamin Lukner

Peter said:
You may want to check out the new Smart Device Framework v1.2

Hi Peter,

Thanks for your reply!
But I'd like to do it with VB, not with C#.
I think the main problem is the string pointer. Do you know how I can
solve this in VB? Every time I want to P/Invoke with a struct containing
a string pointer I get problems.


Kind regards,

Benjamin Lukner
 
P

Peter Foot [MVP]

This is a limitation of the Compact Framework. You have to pass the string
as an IntPtr - which is a pointer to the character data in unmanaged memory.
You can add a reference to OpenNETCF.Drawing.dll to your project and then
call this functionality from a VB.NET application to avoid having to
duplicate all the code necessary to handle this marshalling and define the
LogFont structure etc.

Peter
 
B

Benjamin Lukner

Peter said:
This is a limitation of the Compact Framework. You have to pass the string
as an IntPtr - which is a pointer to the character data in unmanaged memory.
You can add a reference to OpenNETCF.Drawing.dll to your project and then
call this functionality from a VB.NET application to avoid having to
duplicate all the code necessary to handle this marshalling and define the
LogFont structure etc.

ARRGGHH!!

I've found "my" error.

Private Declare Function CreateFontIndirect _
Lib "CoreDLL.dll" _
Alias "CreateFontA"

'Alias "CreateFontIndirect" ' would be much better....

It actually works with the code I've posted!!
But there is another question/problem I have... I'll open a new thread.


Kind regards,

Benjamin Lukner
 

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