title: Managing C++ Garmin API in C#
body: <p>I want to call <a href="http://developer.garmin.com/mobile/mobile-sdk/" rel="nofollow noreferrer">Garmin API</a> 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 throws a <code>NotSupportedException</code> (bad arguments type, I think) in the <code>QueCreatePoint</code> call. Below is the C++ API code and my C# work.</p>
  
  <p>C++ Functions prototype and C# P/Invoke Calls:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>QueErrT16:</p>
  
  <pre><code>typedef uint16 QueErrT16; enum { ... }
  
  public enum QueErrT16 : ushort { ... }
  </code></pre>
  
  <p>QuePointType:</p>
  
  <pre><code>typedef struct
  {
      char                    id[25];
      QueSymbolT16            smbl;
      QuePositionDataType     posn;
  } QuePointType;
  
  public struct QuePointType
  {
      public string id;
      public QueSymbolT16 smbl;
      public QuePositionDataType posn;
  }
  </code></pre>
  
  <p>QueSymbolT16:</p>
  
  <pre><code>typedef uint16 QueSymbolT16; enum { ... }
  
  public enum QueSymbolT16 : ushort { ... }
  </code></pre>
  
  <p>QuePositionDataType:</p>
  
  <pre><code>typedef struct
  {
      sint32      lat;
      sint32      lon;
      float       altMSL;
  } QuePositionDataType;
  
  public struct QuePositionDataType
  {
      public int lat;
      public int lon;
      public float altMSL;
  }
  </code></pre>
  
  <p>QuePointHandle:</p>
  
  <pre><code>typedef uint32 QuePointHandle;
  </code></pre>
  
  <p>In C# I manage it as a <code>uint</code> var.</p>
  
  <p>And this is my current C# function to call all this:</p>
  
  <pre><code>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; 
  }
  </code></pre>