I’m trying to iterate the items in a notes document using the com api from c++, but it doesn’t seem to work properly. If anyone could point out a problem with my code, I’d be grateful. I’m using the IDocument.Items property.
Here’s some sample code of what I’m doing:
// note that in my “real” code, I check the return values from all functions
// just not showing it (or other validation) here for brevity
// doc is a valid IDocumentPtr
int dims = 0;
int count = 0;
long lwr = 0;
long upr = 0;
// get the array of items
VARIANT var = doc->Items;
// var.vt == 8204 == VT_VARIANT|VT_ARRAY
dims = var.parray->cDims;
count = var.parray->rgsabound[0].cElements;
SafeArrayGetLBound( var.parray, 1, &lwr );
SafeArrayGetUBound( var.parray, 1, &upr );
// at this point for my particular document
// dims = 1, count = 7, lwr = 0, upr = 6
VARIANT *pData = NULL;
SafeArrayAccessData( var.parray, (void**)pData;
for ( long i = lwr; i <= upr; i++ ) {
// pData now points to a valid array of variants
// Here’s the Problem:
// pData[i].vt == 0 == VT_EMPTY
// None of the variants in the array contains
// any useful data
}
SafeArrayUnaccessData( var.parray );
So, I get an array of absolutely useless variants. Am I doing something wrong in how I’m getting the Notes document’s items? Or am I just iterating over the SAFEARRAY’s items incorrectly? (I don’t think there’s a problem with the way I’m doing it…otherwise I wouldn’t bother other people with it).
Yes, I probably could use the C api and callbacks to get all the items, but that’s not the point. If there’s a method in the COM api, shouldn’t I be able to make use of it?
Thanks,
Ben Klassen