views:

52

answers:

3

I have a C++ project with the following definition in the header file:

typedef enum                        /* Set operation type                */
{
  GPC_DIFF,                         /* Difference                        */
  GPC_INT,                          /* Intersection                      */
  GPC_XOR,                          /* Exclusive or                      */
  GPC_UNION                         /* Union                             */
} gpc_op;

typedef struct                      /* Polygon vertex structure          */
{
  double              x;            /* Vertex x component                */
  double              y;            /* vertex y component                */
} gpc_vertex;

typedef struct                      /* Vertex list structure             */
{
  int                 num_vertices; /* Number of vertices in list        */
  gpc_vertex         *vertex;       /* Vertex array pointer              */
} gpc_vertex_list;

typedef struct                      /* Polygon set structure             */
{
  int                 num_contours; /* Number of contours in polygon     */
  int                *hole;         /* Hole / external contour flags     */
  gpc_vertex_list    *contour;      /* Contour array pointer             */
} gpc_polygon;

void gpc_polygon_clip        (gpc_op           set_operation,
                              gpc_polygon     *subject_polygon,
                              gpc_polygon     *clip_polygon,
                              gpc_polygon     *result_polygon);

And I compile it in VS 2008. It can compile! So far so good.

Next I want to call the C++ dll from .Net, and I do a standard PInvoke:

[DllImport("gpc.dll")]
private static extern void gpc_polygon_clip([In]     GpcOperation set_operation,
                                            [In]     ref gpc_polygon subject_polygon,
                                            [In]     ref gpc_polygon clip_polygon,
                                            [In, Out] ref gpc_polygon result_polygon);

But when I run the code, I get an "unable to find an entry point name * in DLL 'gpc.dll'".

I think my C++ vcproj setting must be wrong, because it seems that the definition is not exported. Any idea how to fix this?

+1  A: 

gpc_polygon_clip is not market for export. It should use __declspec( dllexport ). Have a look here.

Jaka
+1  A: 

There are a number of ways. Probably the easiest is to prefix __declspec(dllexport) / __declspec(dllimport) to the declaration (when compiling the DLL or using it, respectively)

MSalters
+3  A: 
extern "C" __declspec(dllexport) void gpc_polygon_clip        (gpc_opset_operation,
                              gpc_polygon     *subject_polygon,
                              gpc_polygon     *clip_polygon,
                              gpc_polygon     *result_polygon);

try out above in c++ vc project.

user001