Garmin API, P/Invoke, Marshing, C#
Publicado por borjolujo (1 intervención) el 11/09/2009 11:41:45
Querría usar la API de Garmin (http://developer.garmin.com/mobile/mobile-sdk/) en un proyecto de VB.Net Compact Framework. La API esta en C++ y usa punteros, así que me estoy haciendo un proyecto intermedio en C#. Estoy encontrandome problemas al ejecutar mi codigo ya que lanza NotSupportedException (creo que por que el tipo de los argumentos es incorrecto) al llamar a la función QueCreatePoint. Aquí esta el código de la API y mi conversión a C#.
-- 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.
-- Y éste es el código de la función que hace uso de todo lo anterior ----------
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;
}
Apreciaré cualquier ayuda. Muchas gracias.
-- 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.
-- Y éste es el código de la función que hace uso de todo lo anterior ----------
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;
}
Apreciaré cualquier ayuda. Muchas gracias.
Valora esta pregunta


0