DrawPolygon Crash

long handle = m_Map.NewDrawing(mapWindow::PROJECTION_WGS84);

double projx[5], projy[5];
CRect rect;
m_Map.PixelToProj(0, 0, projx, projy);
m_Map.PixelToProj(rect.Width() / 2, 0, projx + 1, projy + 1);
m_Map.PixelToProj(rect.Width() / 2, rect.Height() / 2, projx + 2, projy + 2);
m_Map.PixelToProj(0, rect.Height() / 2, projx + 3, projy + 3);
m_Map.PixelToProj(0, 0, projx + 4, projy + 4);

bound.lLbound = 0;
bound.cElements = 5;
SAFEARRAY *psaX = SafeArrayCreate(VT_R8, 1, &bound);
SAFEARRAY *psaY = SafeArrayCreate(VT_R8, 1, &bound);
for (int i = 0; i < 5; i++)
	long ind = i;
	SafeArrayPutElement(psaX, &ind, projx + i);
	SafeArrayPutElement(psaY, &ind, projy + i);

VARIANT varX, varY;
varX.vt = VT_ARRAY | VT_R8 | VT_BYREF;
varY.vt = VT_ARRAY | VT_R8 | VT_BYREF;
varX.pparray = &psaX;
varY.pparray = &psaY;

m_Map.DrawPolygonEx(handle, &varX, &varY, 5, RGB(0, 0, 255), TRUE, 30);

delete[] psaX, psaY;


Hello @liguojun

Regarding your comments on GitHub recommending the definition change from VTS_VARIANT to VTS_PVARIANT in the DrawPolygonEx method…

I’m still looking into this. The definitions of VTS_VARIANT and VTS_PVARIANT in afxdisp.h are as follows:

#define VTS_VARIANT         "\x0C"      // a 'const VARIANT&' or 'VARIANT*'
#define VTS_PVARIANT        "\x4C"      // a 'VARIANT*'

So it would appear that the VTS_VARIANT is not inappropriate with the parameters being VARIANT*

I do not want to change the definition without knowing it is in error, since it is potentially a breaking change for all previous users. I have successfully used this function as it is currently defined (albeit from a VB6 application, which can be a little mysterious about how it handles certain parameter types). It would be a little bit of work for me to set up an MFC-based test. Would you be willing to share your MFC code (or some subset) so that I could debug the OCX with it?



I do notice that your initial call to StartDrawing is not handing in a correct parameter.

long handle = m_Map.NewDrawing(mapWindow::PROJECTION_WGS84);

The call to NewDrawing does not take the projection itself, but rather an enumeration indicating that the coordinates are either in screen coordinates or spatially referenced coordinates. See the documentation here.

Based on your usage of screen coordinates I would try the following:

long handle = m_Map.NewDrawing(tkDrawReferenceList.dlScreenReferencedList);

Please see if that makes a difference.