[StructLayout(LayoutKind.Sequential)]
struct SHPObject
{
public int nSHPType;
public int nShapeId;
public int nParts;
public IntPtr panPartStart;
public IntPtr panPartType;
public int nVertices;
public IntPtr padfX;
public IntPtr padfY;
public IntPtr padfZ;
public IntPtr padfM;
public double dfXMin;
public double dfYMin;
public double dfZMin;
public double dfMMin;
public double dfXMax;
public double dfYMax;
public double dfZMax;
public double dfMMax;
};
[DllImport("shapelib.dll", CharSet = CharSet.Ansi, EntryPoint = "SHPReadObject", CallingConvention=CallingConvention.Cdecl)]
private static extern IntPtr internalSHPReadObject(SHPInfo hSHP, int ishape);
............
............
public static SHPObject SHPReadObject(SHPInfo hSHP, int ishape)
{
IntPtr ptr = internalSHPReadObject(hSHP, ishape);
return (SHPObject)Marshal.PtrToStructure(ptr, typeof(SHPObject));
}
....
....
SHPObject SHPAPI_CALL1(*)
SHPReadObject( SHPHandle psSHP, int hEntity )
{
SHPObject *psShape;
/* -------------------------------------------------------------------- */
/* Validate the record/entity number. */
/* -------------------------------------------------------------------- */
if( hEntity < 0 || hEntity >= psSHP->nRecords )
return( NULL );
.........
.........
psShape = (SHPObject *) calloc(1,sizeof(SHPObject));
psShape->nShapeId = hEntity;
........
........
return (psShape);
//#define SHPAPI_CALL __declspec(dllexport) __stdcall
//#define SHPAPI_CALL1 __declspec(dllexport) * __stdcall
#ifdef SHAPELIB_DLLEXPORT
# define SHPAPI_CALL __declspec(dllexport)
# define SHPAPI_CALL1(x) __declspec(dllexport) x
#endif
#ifndef SHPAPI_CALL
# define SHPAPI_CALL
#endif
#ifndef SHPAPI_CALL1
# define SHPAPI_CALL1(x) x SHPAPI_CALL
#endif