Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Drawing / September 2003

Tip: Looking for answers? Try searching our database.

How to use GetGlyphOutline GDI32 API with C# ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexandre CHATTON - 29 Sep 2003 08:56 GMT
Hello,

I'm trying to integrate the GetGlyphOutline API in a C#
project. My algorithm is working fine with VB6, but I still have problem to
make the appropriate
definitions using C#. Anybody has a solution ?

Declares:

[StructLayout(LayoutKind.Sequential)]
public struct FIXED
{
public int fract;
public int Value;
}

[StructLayout(LayoutKind.Sequential)]
public struct MAT2
{
[MarshalAs(UnmanagedType.Struct)] public PhoebeReport.FIXED eM11;
[MarshalAs(UnmanagedType.Struct)] public PhoebeReport.FIXED eM12;
[MarshalAs(UnmanagedType.Struct)] public PhoebeReport.FIXED eM21;
[MarshalAs(UnmanagedType.Struct)] public PhoebeReport.FIXED eM22;
}

[StructLayout(LayoutKind.Sequential)]
public struct POINTAPI
{
public int x;
public int y;
}

[StructLayout(LayoutKind.Sequential)]
public struct GLYPHMETRICS
{
public int gmBlackBoxX;
public int gmBlackBoxY;
[MarshalAs(UnmanagedType.Struct)] public PhoebeReport.POINTAPI
gmptGlyphOrigin;
public int gmCellIncX;
public int gmCellIncY;
}

'****************************

[DllImport("gdi32.dll")]
public static extern IntPtr GetGlyphOutline (IntPtr hdc, int uChar, int
fuFormat, [In, Out] PhoebeReport.GLYPHMETRICS lpgm, int cbBuffer, [In, Out]
object lpBuffer, PhoebeReport.MAT2 lpmat2);

'****************************

and Call

lpMatrix = new PhoebeReport.MAT2();
lpMatrix.eM11.Value = 1;
lpMatrix.eM22.Value = 1;
lpGlyph = new PhoebeReport.GLYPHMETRICS();
oObj = null;
iRet = GetGlyphOutline(hDC, 0x48, PhoebeReport.FontManager.GGO_METRICS,
lpGlyph, 0, oObj, lpMatrix);

Signature

Thanks

Bob Powell [MVP] - 29 Sep 2003 12:58 GMT
OTTOMH I would suggest that the structure definitions might need more strict
specifications. For example you may wish to specify Int16 instead of int.

For Example, in your definition of GLYPMETRICS you've specified "int"
instead of Int16 for the fields that are marked "short" in the Win32
definition.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

> Hello,
>
[quoted text clipped - 60 lines]
> --
> Thanks
Mattias Sj?gren - 29 Sep 2003 15:52 GMT
Alexandre,

>[StructLayout(LayoutKind.Sequential)]
>public struct FIXED
>{
>public int fract;
>public int Value;
>}

As Bob said, those members should be shorts, not ints.

public struct FIXED
{
 public short fract;
 public short Value;
}

>[StructLayout(LayoutKind.Sequential)]
>public struct GLYPHMETRICS
[quoted text clipped - 6 lines]
>public int gmCellIncY;
>}

gmCellIncX and gmCellIncY should also be short members.

>[DllImport("gdi32.dll")]
>public static extern IntPtr GetGlyphOutline (IntPtr hdc, int uChar, int
>fuFormat, [In, Out] PhoebeReport.GLYPHMETRICS lpgm, int cbBuffer, [In, Out]
>object lpBuffer, PhoebeReport.MAT2 lpmat2);

The declaration should be

[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
public static extern int GetGlyphOutline (IntPtr hdc, int uChar, int
fuFormat, out PhoebeReport.GLYPHMETRICS lpgm, int cbBuffer, IntPtr
lpBuffer, ref PhoebeReport.MAT2 lpmat2);

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.