DropMany method

K

kbpartha

Hello All,


I wrote a small code to use dropMany using the master shapes in a
stencil.But the DropMany fails.

Can anybody tell me what I am doing wrong.

With Regards
Partha

int RunDemo(void)
{
// This example drops each master in the document stencil of the
// presently active document onto the first page of that
// document using DropMany.
//
HRESULT hr;
CVisioApplication app;
CVisioDocument doc;
CVisioDocuments docs;
CVisioPages pages;
CVisioPage page;
CVisioDocument docStencil;
CVisioMasters masters;
CVisioMaster master;
VBstr vbstrPath,vbstrGuid;
CString sPath = "D:\\Stencil.vss";
short nmasters;

// This sequence gets first page of active document and
// number of masters in document stencil of active document.

if ( VAO_SUCCESS != vaoGetObjectWrap(app) )
goto CU;

hr= app.ActiveDocument(doc);
check_valid(hr, doc);

hr= app.Documents(docs);
check_valid(hr, docs);

/*hr= doc.Pages(pages);
check_valid(hr, pages);

hr= pages.Item(VVariant(1L), page);
check_valid(hr, page);

hr= doc.Masters(masters);
check_valid(hr, masters); */
vbstrPath = sPath;
hr = docs.OpenEx(vbstrPath,visOpenRO | visOpenDocked |visOpenDontList
,docStencil);
check_valid(hr, docStencil);

hr= docStencil.Masters(masters);
check_valid(hr, masters);

hr= masters.Count(&nmasters);
if ( NOERROR != hr )
goto CU;

// Set up arguments to drop many. We're going to make an
// array with nmasters entries which will hold the index of
// each master we want to drop, i,e. 1,2,3,4,5... This is an
// array of variants. We could also set entries to be references
// to objects, or to names of masters to drop. See DropMany
// remarks. For this example, we set up the array of xy
// positions indicating where on the page to drop the masters
// to arbitrary values.

SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 1;
rgsabound[0].cElements = nmasters;

SAFEARRAY FAR *psaObjs;

if ( (psaObjs = SafeArrayCreate(VT_VARIANT,1,rgsabound)) )
{
VARIANT *pObj;
if ( (NOERROR == SafeArrayAccessData(psaObjs,(void**)&pObj)) )
{
SAFEARRAY FAR *psaXY;
rgsabound[0].cElements = nmasters*2;
if ( (psaXY = SafeArrayCreate(VT_R8,1,rgsabound)) )
{
long ix[1], iy[1],iz[1];
*ix = 1; *iy = 2; *iz = 1;
double x, y;
for ( LONG i = 1; i <= nmasters; i++, *ix +=2, *iy += 2 )
{
hr = masters.Item(VVariant(i),master);
check_valid(hr, master);
//get the stencil master and add to the array
pObj.vt = VT_UNKNOWN;
pObj.punkVal = master.GetIP();
x = y = 1.0 + i;
SafeArrayPutElement(psaXY, ix, &x);
SafeArrayPutElement(psaXY, iy, &y);
}

// DropMany will return an array of the ids of the
// shapes it produces and the number of entries in
// psaXY that it successfully processed. psaIDs is
// an out arg created by DropMany and which this
// owes Destroy of.

short nXYsProcessed;
SAFEARRAY FAR *psaIDs = NULL;

hr = page.DropMany(&psaObjs,&psaXY,&psaIDs,&nXYsProcessed);


if ( psaIDs )
SafeArrayDestroy(psaIDs);
SafeArrayDestroy(psaXY);
}
SafeArrayUnaccessData(psaObjs);
}
SafeArrayDestroy(psaObjs);
}
CU:
return 0;
}
 

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

Top