473,811 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managing C++ Garmin API in C#

3 New Member
I want to call Garmin API (http://developer.garmi n.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 NotSupportedExc eption (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("QueA PI.dll")]
    private static extern QueErrT16 QueCreatePoint( ref QuePointType point, ref uint handle);

    [DllImport("QueA PI.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;
    QuePositionData Type posn;
    } QuePointType;
    .
  • public struct QuePointType
    {
    public string id;
    public QueSymbolT16 smbl;
    public QuePositionData Type posn;
    }


-- QueSymbolT16 ----------
  • typedef uint16 QueSymbolT16; enum { ... }
    .
  • public enum QueSymbolT16 : ushort { ... }


-- QuePositionData Type ----------
  • typedef struct
    {
    sint32 lat;
    sint32 lon;
    float altMSL;
    } QuePositionData Type;
    .
  • public struct QuePositionData Type
    {
    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 4507
Plater
7,872 Recognized Expert Expert
NotSupportedExc eption 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
borjolujo
3 New Member
I think the problem is in the P/Invoke call:

[DllImport("QueA PI.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("QueA PI.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: QuePositionData Type (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 Recognized Expert Expert
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
5337
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 "amateur hacker" :-) was very pleased to discover at one stage how to run processes in parallel using python, which is powerful technology to say the least, applicable not only in my project but in lots of other areas as well. Anyway, what I...
3
1514
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 manager class as Singleton. User access to firewire camera objects should only be accessable via refereces obtained from this manager class. I want to avoid the creation of more than one camera object accessing the same physical camera.
7
3621
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, and everytime i need to make a change, I have to switch the names, test, then rename again, obfuscate to the original file name (because this is the file referenced in php/perl/asp whatever files). So its kind of a pain. Any thoughts out...
2
1753
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 managing list boxes. but i need help on managing multiple text boxes. please give a quick reaply. thank you
10
5232
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 another discussion, Garmin and pyUSB don't work together because of the way Garmin installs in Windows. Can anyone explain why? And is there a workaround for this? Really, the simplest way to get this to work is to buy another GPS, but I would like to...
1
2830
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 off the device afterwards so I can plot my rides into MS MapPoint. Thanks for any advice which you can provide. Joseph Geretz
0
6834
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# ! Now that I have that out of the way... I want to write an application that will open multiple Garmin GPX files and display them in a tree view (The filename being the Text, with 2 sub-nodes), so that I can drag waypoints from one file to...
2
1845
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
9724
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10394
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5552
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.