473,387 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Managing C++ Garmin API in C#

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 ----------

Expand|Select|Wrap|Line Numbers
  1. public static QueErrT16 GarminNavigateToCoordinates(double latitude , double longitude)
  2. {
  3.     QueErrT16 err = new QueErrT16();
  4.  
  5.     // Open API
  6.     err = QueAPIOpen();
  7.     if(err != QueErrT16.queErrNone) 
  8.     {
  9.         return err;
  10.     }
  11.  
  12.     // Create position
  13.     QuePositionDataType position = new QuePositionDataType();
  14.     position.lat = GradosDecimalesASemicirculos(latitude);
  15.     position.lon = GradosDecimalesASemicirculos(longitude);
  16.  
  17.     // Create point
  18.     QuePointType point = new QuePointType();
  19.     point.posn = position;
  20.  
  21.     // Crete point handle
  22.     uint hPoint = new uint();
  23.  
  24.     err = QueCreatePoint(ref point, ref hPoint);  // HERE i got a NotSupportedException
  25.     if (err == QueErrT16.queErrNone) 
  26.     {
  27.         err = QueRouteToPoint(hPoint);
  28.     }
  29.  
  30.     // Close API
  31.     QueAPIClose();
  32.  
  33.     return err; 
  34. }

I will appreciate any help. Thanks.
Sep 11 '09 #1
3 4489
Plater
7,872 Expert 4TB
NotSupportedException is generally thrown when you try to use a property/function that is not available in the current implentation.
This could be caused by a number of things.
One of which is using the compact framework, which has limited support or some classes/etc
The other is in inheritance, some derived classes will not use a property/method but the base class has it so it will be listed
Sep 11 '09 #2
I think the problem is in the P/Invoke call:

[DllImport("QueAPI.dll")]
private static extern QueErrT16 QueCreatePoint(ref QuePointType point, ref uint handle);

for the C prototype:

QueAPIExport QueErrT16 QueCreatePoint( const QuePointType* point, QuePointHandle* handle );

The parameter are not correct, the API want a pointer and i´m sending var with ref attribute. But when i write this:

[DllImport("QueAPI.dll")]
private static extern QueErrT16 QueCreatePoint(QuePointType* point, uint* handle);

i can´t compile because an error: "Cannot take the address of, get the size of, or declare a pointer to a managed type 'QuePointType'." This is because QuePointType contains a managed type: QuePositionDataType (Pointer types: http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx).

So, i dont know how to send to the function a pointer of my structure.
Sep 14 '09 #3
Plater
7,872 Expert 4TB
Your structure is a managed structure then, not pulled from the DLL (if that can even be done)
Have you tried just passing in an IntPtr and then trying to create an object from it?
Sep 14 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andrei D. | last post by:
Hello Python newsgroup, In the process of developing a big ssh wrapper for sending commands to multiple hosts over the last few months, I (almost accidentally, considering I'm really just an...
3
by: Torsten Wiebesiek | last post by:
Hi, I am currently working on a computer vision system. At the moment I'm adding support for firewire cameras. Since there is only one firewire system on a computer, I have writen a firewire...
7
by: tgh003 | last post by:
I would be interested to hear how others are managing their javascript (.js) files from the original code vs the obfuscated version they publish to their site/webapp. I currently manage 2 files,...
2
by: fariba123 | last post by:
i have designed an employee information site. there is an option to generate pay slip. how can i show the employee related data based on the drop down list. i have found code example for...
10
by: robingfx | last post by:
Hello, I am starting this discussion in an effort to get my Garmin GPS to work with pyUSB, and a place to exchange information and code appropriate for this topic. According to bartonc, in...
1
by: Joseph Geretz | last post by:
Anyone write code to interface with the Garmin Edge via USB? (Or Forerunner - I think these are pretty much the same.) I'm not looking for real-time GPS feed, but rather I'd like to get the data...
0
by: Skywave | last post by:
Hi All Firstly: I have searched everywhere! I couldn't find anything! Secondly: I am VERY new (1 and a half days) to C#, but I have been doing VB6 and VB.Net for years now. I want to learn C# ! ...
2
by: =?Utf-8?B?Um9iZQ==?= | last post by:
Hi, I need that someone suggest me some library for .NET Framework to create an application that use a Garmin's GPS device. Thanks.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.