how to read the values in safearray

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

Reply to
syshieley
Loading thread data ...

Have you tried _type casting_?

For example

pSWBody = (IBody2*) pBodyDispArray[i];

-h-

Reply to
Heikki Leivo

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

Reply to
syshieley

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.