I'm translating this dll call for the "Clipper" polygon clipping library (version 2):
__declspec(dllimport) bool __stdcall ClipperFree(void *);
I'm not sure what a void pointer needs to become. Any help would be great. I've read a book on C, but I never actually use C.
My translation (doesn't seem to be working with the DLL)
Declare Function ClipperFree Lib "clipper.dll" Alias "ClipperFree" (clipper As DWord) As Boolean
Thanks!
Joseph
Charles Pegge
27-04-2011, 06:15
Hi Joseph,
When you see void* it usually means pointer to an unspecified structure. You can treat this like any other kind of handle so Byval Long or Byval Dword will suffice.
Bool I would specify as Long.
Thus:
declare function ClipperFree Lib "clipper.dll" Alias "ClipperFree" (byval clipper as long) as long
Charles
Thanks Charles! Your suggestions worked like a charm and I'm able to use the polygon clipping library "clipper" perfectly.
http://angusj.com/delphi/clipper.php
Here's my code below for anyone who may be interested in using that library. Note that you have to use it with version 2 of clipper, as the newer ones don't have a DLL build.
' Polygon Clipping
' Needs Clipper v2 DLL
Uses "Console"
/* ///////////////////////////////////////////////////////////////////
polygons are passed To And from Clipper through arrays of float
Using the following format:
flt(0) = polygon Count
flt(1) = polygon(0).vertex Count
flt(2) = polygon(0).vertex(0).X;
flt(3) = polygon(0).vertex(0).Y;
flt(4) = polygon(0).vertex(1).X;
flt(5) = polygon(0).vertex(1).Y;
...
flt(n) = polygon(1).vertex Count
flt(n+1) = polygon(1).vertex(0).X;
flt(n+2) = polygon(1).vertex(0).Y;
...
Any Type of polygon (concave, self-intersecting etc) And Any
numbers of polygons can be added to the clipping task through
the ClipperAddPolygon() function. With simple polygons, 'holes'
are inferred by the position of polygons within other polygons
of the same type (ie ptSubject or ptClip).
////////////////////////////////////////////////////////////////// */
Local p(8) As Single
p(1) = 1 ' 1 polygon stored in this array
p(2) = 3 ' 3 nodes in the first polygon
p(3) = 10 'x1
p(4) = 40 'y1
p(5) = 30 'x2
p(6) = 50 'y2
p(7) = 30 'x3
p(8) = 20 'y3
Local g(8) As Single
g(1) = 1 ' 1 polygon
g(2) = 3 ' 4 nodes
g(3) = 10 ' x1
g(4) = 20 ' y1...
g(5) = 40
g(6) = 30
g(7) = 25
g(8) = 45
' Clipper Enumerations:
' Polygon use
Global Clipper_ptSubject As Integer = 0 ' The subject polygon
Global Clipper_ptClip As Integer = 1 ' The polygon to clip the subject with.
' Polygon Filling
Global Clipper_pftEvenOdd As Integer = 0
Global Clipper_pftNonZero As Integer = 1
' Clipping Operation
Global Clipper_ctIntersection As Integer = 0
Global Clipper_ctUnion As Integer = 1
Global Clipper_ctDifference As Integer = 2
Global Clipper_ctXor As Integer = 3
' Clipper DLL Functionality:
Declare Function ClipperCreate Lib "clipper.dll" Alias "ClipperCreate" () As Long
Declare Function ClipperFree Lib "clipper.dll" Alias "ClipperFree" (ByVal clipper As Long) As Long
Declare Function ClipperClear Lib "clipper.dll" Alias "ClipperClear" (ByVal clipper As Long) As Long
Declare Function ClipperAddPolygon Lib "clipper.dll" Alias "ClipperAddPolygon" _
(ByVal clipper As Long, ByRef polygon() As Single, ByVal clipOrSubj As Long) As Long
Declare Function ClipperExecute Lib "clipper.dll" Alias "ClipperExecute" _
(ByVal clipper As Long, ByVal operation As Integer, ByRef count As Long, ByVal evenoddOrNonzero1 As Long,_
ByVal evenoddOrNonzero2 As Long) As Long
Declare Function ClipperSolution Lib "clipper.dll" Alias "ClipperSolution" _
(ByVal clipper As Long, ByRef polygon() As Single, ByVal count As Long) As Long
Local clipper As DWord
Local s() As Single ' Final polygon solution
Dim solution As Integer = 0 ' Number of array items in the solution array
clipper = ClipperCreate()
PrintL "Clipper: " & clipper
PrintL "Add Polygon: " & ClipperAddPolygon(clipper, g, Clipper_ptSubject) ' Add the subject polygon.
PrintL "Add Polygon: " & ClipperAddPolygon(clipper, p, Clipper_ptClip) ' Add the clipping polygon.
PrintL "Execute: " & ClipperExecute(clipper, Clipper_ctUnion,_
solution, Clipper_pftNonZero, Clipper_pftNonZero)
PrintL "Solution Array Length: " & solution
ReDim s(solution)
Local i As Integer
' Fill in the solution data
ClipperSolution(clipper, s, solution)
Local polynodes As Integer = s(2) ' Get the number of nodes
PrintL "Solution Polygon Vertices: " & polynodes
For i = 3 To UBound(s) Step 2
'PrintL " *Node: " & s(i) & "," & s(i+1)
Next
PrintL
PrintL "Raw Data: "
For i = 1 To UBound(s)
PrintL "Data: " & s(i)
Next
PrintL "ClipperFree: " & ClipperFree(clipper)
WaitKey