|
-
March 30th, 2008, 04:14 AM
#1
COM and IDispatch
I have the following code:
Code:
// Get all of the children components from this m_Component object
_variant_t componentChildren = pComponent->GetChildren();
The returned variant contains a SafeArray of IDispatch pointers. I have verified that the count of the SafeArray is correct, but the IDispatch pointers are all NULL.
I extract the array elements like below:
Code:
if ((componentChildren.vt == VT_EMPTY) || (V_VT(&componentChildren) == VT_NULL)) // Error - array is empty or null
return 0;
SAFEARRAY* psa = V_ARRAY(&componentChildren);
HRESULT hres = SafeArrayAccessData(psa, (void **)pChildren);
long highIndex;
SafeArrayGetUBound(psa, 1, &highIndex); // Get index number of highest array element
// The array range is from 0 to highIndex
long childrenCount = highIndex + 1; // Actual # of array elements is highIndex + 1
if(pChildren)
{
// Recursively traverse the children
for (int i = 0; i < childrenCount; i++) // For each child component
{
TraverseChildren(RecurseLevel, pChildren[i]);
}
}
The pChildren[i] causes an access violation error.
What could be the probable reasons for this. Please help I am stuck in this.
If there is no love sun won't shine
-
March 31st, 2008, 12:32 AM
#2
Re: COM and IDispatch
You should use an extra level of indirection:
Code:
HRESULT hres = SafeArrayAccessData(psa, (void **) & pChildren);
With best wishes,
Vita
-----------------------
Russian Software Development Network -- http://www.rsdn.ru
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|