I have a C dll that I'm trying to import. I want to use a single function from the dll. The C definition is:
At the moment I've got this code:
And calling the function with:
But this doesn't work. Any idea's what I'm doing wrong?
Jon
"I don't regret this, but I both rue and lament it.
Code:
long NEAR_FindNearest( char *FileName,
char *Postcode,
long MaxRecords,
double Radius,
NEAREST_INFO *NearestInfo);
typedef struct
{
int Count;
NEAREST_ITEM *NearestList;
} NEAREST_INFO;
typedef struct
{
struct
{
int Eastings;
int Northings;
} Grid;
char *Record;
struct
{
double Kilometres;
double Miles;
} Distance;
} NEAREST_ITEM;
Code:
using System;
using System.Runtime.InteropServices;
namespace NearCode
{
public class NearCode
{
[StructLayout(LayoutKind.Sequential)]
public struct Grid
{
public int Eastings;
public int Northings;
}
[StructLayout(LayoutKind.Sequential)]
public struct Distance
{
public double Kilometres;
public double Miles;
}
[StructLayout(LayoutKind.Sequential)]
public struct NearestItem
{
public Grid Grid;
public string Record;
public Distance Distance;
}
[StructLayout(LayoutKind.Sequential)]
public struct NearestInfo
{
public int count;
public NearestItem NearestItem;
}
[DllImport("NearAPI.dll")]
static extern int NEAR_FindNearest(string FileName, string PostCode, int MaxRecords, double Radius, NearestInfo NearestInfo);
public int FindNearest(string FileName, string PostCode, int MaxRecords, double Radius, NearestInfo NearestInfo)
{
return NEAR_FindNearest(FileName, PostCode, MaxRecords, Radius, NearestInfo);
}
}
}
Code:
NearCode.NearCode nc = new NearCode.NearCode();
NearCode.NearCode.NearestInfo ni = new NearCode.NearCode.NearestInfo();
Console.Write(nc.FindNearest("nearest.txt", "OX183PW", 12, 12, ni).ToString());
Jon
"I don't regret this, but I both rue and lament it.