I want to call Garmin API (http://developer.garmin.com/mobile/mobile-sdk/) in VB.Net Compact Framework project. The API is in C++, so i´m making a C# dll project as intermediate way between API dll and VB.Net. I have some problems while executing my code because it throw a NotSupportedException (bad arguments type, i think) in QueCreatePoint call. Here is the C++ API code, and my C# work:
-- C++ Functions prototype and C# P/Invoke Calls ----------
QueAPIExport QueErrT16 QueCreatePoint( const QuePointType* point, QuePointHandle* handle );
QueAPIExport QueErrT16 QueClosePoint( QuePointHandle point );
[DllImport("QueAPI.dll")] private static extern QueErrT16 QueCreatePoint(ref QuePointType point, ref uint handle);
[DllImport("QueAPI.dll")] private static extern QueErrT16 QueRouteToPoint(uint point);
-- QueErrT16 ----------
typedef uint16 QueErrT16; enum { ... }
public enum QueErrT16 : ushort { ... }
-- QuePointType ----------
typedef struct { char id[25]; QueSymbolT16 smbl; QuePositionDataType posn; } QuePointType;
public struct QuePointType { public string id; public QueSymbolT16 smbl; public QuePositionDataType posn; }
-- QueSymbolT16 ----------
typedef uint16 QueSymbolT16; enum { ... }
public enum QueSymbolT16 : ushort { ... }
-- QuePositionDataType ----------
typedef struct { sint32 lat; sint32 lon; float altMSL; } QuePositionDataType;
public struct QuePositionDataType { public int lat; public int lon; public float altMSL; }
-- QuePointHandle ----------
typedef uint32 QuePointHandle;
In C# i manage it as uint var.
-- And this is my current C# function to call all this ----------
public static QueErrT16 GarminNavigateToCoordinates(double latitude , double longitude)
{
QueErrT16 err = new QueErrT16();
// Open API
err = QueAPIOpen();
if(err != QueErrT16.queErrNone)
{
return err;
}
// Create position
QuePositionDataType position = new QuePositionDataType();
position.lat = GradosDecimalesASemicirculos(latitude);
position.lon = GradosDecimalesASemicirculos(longitude);
// Create point
QuePointType point = new QuePointType();
point.posn = position;
// Crete point handle
uint hPoint = new uint();
err = QueCreatePoint(ref point, ref hPoint); // HERE i got a NotSupportedException
if (err == QueErrT16.queErrNone)
{
err = QueRouteToPoint(hPoint);
}
// Close API
QueAPIClose();
return err;
}
I will appreciate any help. Thanks.