how to read the values in safearray

Jul 26, 2006 2 Replies

Dear all



i want to access every body in the opened part, there is an example in SolieWorks API for it and i was carrying on based on it. But a problem for me, after using pPartDoc->GetBodies2(swAllBodies, FALSE, &vBodies) to get the bodies data which is vBodies and in variant. i cannot read every body information from it. based on the example in API, i did almost in the same way:



pPartDoc->GetBodies2(swAllBodies, FALSE, &vBodies); SAFEARRAY* psaBody = V_ARRAY(&vBodies); LPDISPATCH* pBodyDispArray = NULL; long nBodyHighIndex = -1; long nBodyCount = -1;



hr = SafeArrayAccessData(psaBody, (void **) &pBodyDispArray); ASSERT(S_OK == hr); ASSERT(NULL != pBodyDispArray); hr = SafeArrayGetUBound(psaBody, 1, &nBodyHighIndex); ASSERT(S_OK == hr); nBodyCount = nBodyHighIndex + 1; for (i = 0; i < nBodyCount; i++) { LPBODY2 pSWBody; pSWBody = pBodyDispArray[i]; ASSERT(pSWBody); hr = pSWBody->Select(VARIANT_TRUE, 0, &bRet); ASSERT(bRet); pSWBody->Release(); } hr = SafeArrayUnaccessData(psaBody); hr = SafeArrayDestroy(psaBody);


there is error duding compiling, it is said it is wrong to do pSWBody = pBodyDispArray[i]; because error C2440: '=' : cannot convert from 'struct IDispatch *' to 'struct IBody2 *' i am really confused, and cannot find a way to read each item in safearray and evaluate it to other object.



thanks for anyhelp you provide....



cheers SY



Have you tried _type casting_?

For example

pSWBody = (IBody2*) pBodyDispArray[i];

-h-

Heikki Leivo =E5=AF=AB=E9=81=93=EF=BC=9A

great!!! it works, thanks so much it wasts me so long time, i would turn here for help earlier

thanks so much

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required