Reputation: 1191
I am trying to specify a vector in an IDL specification of property getter.
I am new to C++ so bear with me. The object IThis
is a hypothetical object of anything.
I am getting a compile error at the id declaration expecting a type specifier. Thank you very much!!!!!!!!!!!!!!!
STDMETHOD(get_ThisList)(vector<IThis*> *value)
{
*value = mThisList;
return S_OK;
}
vector<IThis*> mThisList;
[propget] IDLAPI ThisList([out,retval] vector<IThis*>* value);
Upvotes: 2
Views: 1001
Reputation: 52561
You can't use vector
in a COM interface, with IDL or otherwise. You could return a safearray of interface pointers; it would look like this:
// In IDL
[propget]
HRESULT ThisList([out,retval] SAFEARRAY(IThis*)* value);
// In C++
HRESULT get_ThisList(SAFEARRAY** value);
Other alternatives include a conformant array (though this is inadvisable for an automation interface, as yours appears to be), and a separate collection object that represents a list of objects.
An implementation for get_ThisList
might look something like this:
STDMETHODIMP MyObject::get_ThisList(SAFEARRAY** value) {
if (!value) return E_POINTER;
SAFEARRAYBOUND bound = {mThisList.size(), 0};
*value = SafeArrayCreate(VT_UNKNOWN, 1, &bound);
IUnknown** data;
SafeArrayAccessData(*value, (void**)&data);
for (int i = 0; i < mThisList.size(); ++i) {
(data[i] = mThisList[i])->AddRef();
}
SafeArrayUnaccessData(*value);
return S_OK;
}
Error handling is left as an exercise for the reader.
Upvotes: 3
Reputation: 27365
std::vector is a C++ class; IDL (interface definition language - different language) has no concept of it.
"expecting a type specifier" means the IDL compiler doesn't recognize std::vector as a type.
You will have to return a pointer to array of IThis as the return value, and put it into a smarter object at the caller's site.
Upvotes: 0