Click here to Skip to main content
15,919,778 members
Home / Discussions / C#
   

C#

 
GeneralException Reporting Pin
sreejith ss nair4-May-04 1:13
sreejith ss nair4-May-04 1:13 
GeneralRe: Exception Reporting Pin
Colin Angus Mackay4-May-04 1:28
Colin Angus Mackay4-May-04 1:28 
QuestionHow to customize PropertyGrid ToolTip Pin
LotusM4-May-04 0:53
LotusM4-May-04 0:53 
Generalcombobox datasource Pin
brain2cpu4-May-04 0:21
professionalbrain2cpu4-May-04 0:21 
GeneralRe: combobox datasource Pin
Colin Angus Mackay4-May-04 0:42
Colin Angus Mackay4-May-04 0:42 
GeneralUpdating More than One table Pin
sreejith ss nair3-May-04 23:46
sreejith ss nair3-May-04 23:46 
GeneralRe: Updating More than One table Pin
Heath Stewart4-May-04 4:13
protectorHeath Stewart4-May-04 4:13 
GeneralAlan Murta's - General Polygon Clipper Pin
d-mon3-May-04 22:55
d-mon3-May-04 22:55 
Hi!

I need to use GPC library in a C# project.
GPC library is written in pure C and is available on http://www.cs.man.ac.uk/aig/staff/alan/software/

So what I did is I worte a Win32 .dll with exports of the library functions:
extern "C"
{
__declspec(dllexport) void gpc_add_contour(gpc_polygon *polygon, gpc_vertex_list *contour, int hole);
__declspec(dllexport) void gpc_polygon_clip(gpc_op set_operation, gpc_polygon *subject_polygon, gpc_polygon *clip_polygon, gpc_polygon *result_polygon);
....etc...
}

So I was thinking...ok...now I have the .dll and now I can use C# attribute DllImport to import functions from .dll.

But as you can see there are structures that pass as pointers to the functions. I don't know how to marshal it/make it usable in C#.

This is my current progress in implementing the port of GPC to C# (I don't know when to use IntPtr or something else):
using System;
using System.Text;
using System.Runtime.InteropServices;

namespace nsGPC
{
public class GPC
{
public enum gpc_op
{
GPC_DIFF,
GPC_INT,
GPC_XOR,
GPC_UNION
}

[StructLayout(LayoutKind.Sequential)]
public class gpc_vertex
{
public double x;
public double y;
}

[StructLayout(LayoutKind.Sequential)]
public class gpc_vertex_list
{
public int num_vertices;
public IntPtr vertex; //pointer to gpc_vertex
}

[StructLayout(LayoutKind.Sequential)]
public class gpc_polygon
{
public int num_contours;
public IntPtr hole; //pointer to int
public IntPtr contour; //pointer to gpc_vertex_list
}

[StructLayout(LayoutKind.Sequential)]
public class gpc_tristrip
{
public int num_strips;
public IntPtr strip; //pointer to gpc_vertex_list
}

[DllImport("GPC.NET.dll", CharSet=CharSet.Ansi)]
public static extern void gpc_add_contour(ref gpc_polygon polygon, ref gpc_vertex_list contour, int hole);

[DllImport("GPC.NET.dll", CharSet=CharSet.Ansi)]
public static extern void gpc_polygon_clip(gpc_op set_operation, ref gpc_polygon subject_polygon, ref gpc_polygon clip_polygon, ref gpc_polygon result_polygon);

[DllImport("GPC.NET.dll", CharSet=CharSet.Ansi)]
public static extern void gpc_free_polygon(ref gpc_polygon polygon);

}
}

Well, anyways...Is anyone here with enough knowledge of porting this library to C#?

MP.
GeneralRe: Alan Murta's - General Polygon Clipper Pin
Daniel Turini4-May-04 0:07
Daniel Turini4-May-04 0:07 
GeneralRe: Alan Murta's - General Polygon Clipper Pin
Heath Stewart4-May-04 3:52
protectorHeath Stewart4-May-04 3:52 
GeneralRe: Alan Murta's - General Polygon Clipper Pin
d-mon5-May-04 10:41
d-mon5-May-04 10:41 
QuestionBest C# IRC Channel? Pin
Marlun3-May-04 22:36
Marlun3-May-04 22:36 
AnswerRe: Best C# IRC Channel? Pin
Heath Stewart4-May-04 3:47
protectorHeath Stewart4-May-04 3:47 
GeneralRe: Best C# IRC Channel? Pin
Marlun4-May-04 6:27
Marlun4-May-04 6:27 
GeneralRe: Best C# IRC Channel? Pin
Heath Stewart4-May-04 8:02
protectorHeath Stewart4-May-04 8:02 
GeneralRe: Best C# IRC Channel? Pin
Marlun4-May-04 10:08
Marlun4-May-04 10:08 
GeneralRe: Best C# IRC Channel? Pin
eggie54-May-04 15:54
eggie54-May-04 15:54 
GeneralRe: Best C# IRC Channel? Pin
Marlun4-May-04 20:23
Marlun4-May-04 20:23 
GeneralRe: Best C# IRC Channel? Pin
eggie55-May-04 2:01
eggie55-May-04 2:01 
Generalusing API in C# Pin
nthevu3-May-04 20:18
professionalnthevu3-May-04 20:18 
GeneralRe: using API in C# Pin
Heath Stewart4-May-04 3:46
protectorHeath Stewart4-May-04 3:46 
GeneralRe: using API in C# Pin
nthevu4-May-04 5:15
professionalnthevu4-May-04 5:15 
GeneralRe: using API in C# Pin
Heath Stewart4-May-04 8:00
protectorHeath Stewart4-May-04 8:00 
GeneralRe: using API in C# Pin
nthevu4-May-04 18:18
professionalnthevu4-May-04 18:18 
GeneralAbout WebServer Pin
Moon Boy3-May-04 13:24
Moon Boy3-May-04 13:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.