0

I need a little help in defining the following Windows GDI type in C#. I have the data in the form of a byte[] in C#, and I need to somehow marshal or cast it as the following in C#. I suppose I need to define the proper struct? This is the type:

NAME

META_POLYLINE

NEAREST API CALL

#include <windows.h>
BOOL32 Polyline
(
    HDC32 hdc,
    const POINT32 *pt,
    INT32 count
);

DESCRIPTION

    U16 array no                Value
    --------------------------- --------------
    0                           no of points
    1 each odd until the end    x of the point
    2 each even until the end   y of the point

A polyline is a list of points. Unlike a polygon, a polyline is always unfilled, and can be open.

Jeffrey Hantin
  • 35,734
  • 7
  • 75
  • 94
GdiHelp
  • 7
  • 3

3 Answers3

0

Have you looked at the Polyline entry on PInvoke.net yet?

Zach Johnson
  • 23,678
  • 6
  • 69
  • 86
0

Okay, a metafile record for a polyline... You might want to try doing a Buffer.BlockCopy from the byte array to a UInt16 array.

Jeffrey Hantin
  • 35,734
  • 7
  • 75
  • 94
0
byte[] buffer;
fixed (byte* b = buffer)
{
   ushort* ptr = (ushort*)b;
   int count = (int)*ptr;
   var points = new Point[count];
   for (int i = 0; i < count; i++)
   {
       int x = (int)*(++ptr);
       int y = (int)*(++ptr);
       points[i] = new Point(x, y);
   }
}

(Untested)

dtb
  • 213,145
  • 36
  • 401
  • 431
  • Thank you all. Would I be correct to assume that in my Graphics.EnumerateMetafileProc delegate, the data parameter is the actual GDI object (in this case the Polyline)? – GdiHelp Nov 21 '09 at 00:50
  • I just tested the code above and it worked like a charm. May I ask one more? How do I convert a WmfPolygon to c#? – GdiHelp Nov 21 '09 at 00:58
  • Got Polygon, thanks for the intro. Having trouble with this question if you have a moment please: http://stackoverflow.com/questions/1774291/how-do-i-parse-a-createpenindirect-metafile-record-out-of-a-byte-array – GdiHelp Nov 21 '09 at 02:55