Quantcast
Channel: MapWinGIS ActiveX Map and GIS Component
Viewing all articles
Browse latest Browse all 2341

New Post: C++ DrawPolygon problem?

$
0
0
Hi,

I am having the same issue. I am Using MapWinGIS 4.9.3. I am builing an application using C++ in MSVC 2015.
Here is code snippet:
void plotEllipse(int drawingLayer, double latInDeg, double longInDeg, double majorAxisInM, double minorAxisInM, double angleInDeg, OLE_COLOR plotColour)
{
   VARIANT* xplot = NULL;
   VARIANT* yplot = NULL;
   SAFEARRAY* xsafe = NULL;
   SAFEARRAY* ysafe = NULL;

   double angleInRad = angleInDeg / pi2;
   LONG polyCount = pi2 / 0.01;

   xplot = new VARIANT;
   yplot = new VARIANT;
   VariantInit(xplot);
   VariantInit(yplot);

   SAFEARRAYBOUND rgsabound;
   rgsabound.lLbound = 0;
   rgsabound.cElements = polyCount;

   xplot->vt = VT_ARRAY | VT_BYREF;
   yplot->vt = VT_ARRAY | VT_BYREF;

   xsafe = SafeArrayCreate(VT_R8, 1, &rgsabound);
   xplot->pparray = &xsafe;
   if (xplot->pparray == NULL)
   {
      return;
   }
   ysafe = SafeArrayCreate(VT_R8, 1, &rgsabound);
   yplot->pparray = &ysafe;
   if (yplot->pparray == NULL)
   {
      SafeArrayDestroy(xsafe);
      return;
   }
   double* xd = NULL;
   double* yd = NULL;
   SafeArrayAccessData(xsafe, (void**)&xd);
   SafeArrayAccessData(ysafe, (void**)&yd);
   LONG index = 0;

   double sinAngle = std::sin(angleInRad);
   double cosAngle = std::cos(angleInRad);

   for (double fineValue = 0; fineValue < pi2; fineValue += 0.01)
   {
      double sinStep = std::sin(fineValue);
      double cosStep = std::cos(fineValue);
      double x = (majorAxisInM*cosStep*cosAngle - minorAxisInM*sinStep*sinAngle);
      double y = (majorAxisInM*cosStep*sinAngle - minorAxisInM*sinStep*cosAngle);
      xd[index] = x;
      yd[index] = y;
      index++;
   }
   SafeArrayUnaccessData(xsafe);
   SafeArrayUnaccessData(ysafe);

   map->DrawPolygonEx(drawingLayer, xplot, yplot, polyCount, plotColour, 0);

   SafeArrayDestroy(xsafe);
   SafeArrayDestroy(ysafe);

   VariantClear(xplot);
   VariantClear(yplot);

   delete xplot;
   delete yplot;

   xplot = NULL;
   yplot = NULL;
}
When the application attempts to call the DrawPolygonEx function it crashes (Exception thrown.... Access violation).

My .tlh has this:
#pragma implementation_key(383)
inline HRESULT MapWinGIS::_DMap::DrawPolygonEx ( long LayerHandle, VARIANT * xPoints, VARIANT * yPoints, long numPoints, OLE_COLOR Color, VARIANT_BOOL fill ) {
    return _com_dispatch_method(this, 0x9b, DISPATCH_METHOD, VT_EMPTY, NULL, 
        L"\x0003\x400c\x400c\x0003\x0003\x000b", LayerHandle, xPoints, yPoints, numPoints, Color, fill);
}
Specifically the exception occurs when the _com_dispatch_method is called.

Any help would greatly be appreciated. I have spent hours searching for examples and have found no working results.

Viewing all articles
Browse latest Browse all 2341

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>