DrawPolyline with vc++

V

vdoser

Hi there,
I'm using vc++ and visio automation to create a shape in an opened Visio
2003 doc.
this code works ok for a rectangle( Drawrectangle) but fails for a polyline:

CVPage visPage = m_visioApp.get_ActivePage();
if (visPage.m_lpDispatch)
{

SAFEARRAYBOUND sab;
sab.cElements = 6;
sab.lLbound = 0;

SAFEARRAY* psa = SafeArrayCreate(VT_R8, 1, &sab);

long idx[1];
double valX = 1;
double valY = 3;

for (int i = 0; i < 3 ; i++)
{
idx[0]= i;
SafeArrayPutElement(psaX,idx,&valX);
idx[0]+= 1;
SafeArrayPutElement(psaX,idx,&valY);
valX = valX + 1;
valY = valY + 1;
}

CVShape shape = visPage.DrawPolyline(&psaX, 0); -> "Access violation
writing location" exception

SafeArrayDestroy(psaX);

shape.ReleaseDispatch();
}

What might be wrong?

Any help would be appreiciated,

Serguei
 
N

Nikolay Belyh

Hi there,
I'm using vc++ and visio automation to create a shape in an opened Visio
2003 doc.
this code works ok for a rectangle( Drawrectangle) but fails for a polyline:

Not sure, but it seems you are filling the safearray in an unsafe way.
You leave 2 last items of the array uninitialized.
Maybe passing this unitialized array to DrawPolyline results in this
unexpected behavior.

Your code:
idx[0]= i;

Should be (I suppose):
idx[0] = i*2;

Kind regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top