Re: Using the VB/VBA Collection class in C++ code
First off, you are supposed to simply store a copy of the
original collection in your putref method. That aside, your
bug is using DISPATCH_METHOD instead of DISPATCH_PROPERTYGET.
As I already mentioned, this is a read-only property, not
a method. BTW, you are not checking the return value of
Invoke. If you pass a value for the EXCEPINFO structure,
you may get detailed error information too (for debugging
purposes, no point doing it in a release build...).
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Rob Perkins" <finitedev@community.nospam> wrote in message
news:4l9n0nFtt2mU1@individual.net...
Alexander Nickolov wrote:
Ah, you simply accept IDispatch* as the property type.
My explanation was how you use the collection, accepting
it is trivial...
Not so trivial.
My code in VB reads:
Dim c As New Collection
'fill collection here ...
Dim m As New ClassWithIDispatchProperty
Set m.FilesCollection = c
...where FilesCollection is the IDispatch property. putref_ looks like
this:
STDMETHODIMP ClassWithIDispatchProperty::putref_FilesCollection(IDispatch*
newVal)
{
// TODO: Add your implementation code here
unsigned int * puArgErr = 0;
VARIANT result;
VariantInit(&result);
newVal->Invoke(-4,
IID_NULL,
(LCID)MAKELCID(MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL), SORT_DEFAULT),
DISPATCH_METHOD,
NULL,
&result,
NULL,
puArgErr);
if (result.vt==VT_UNKNOWN) {
if (FAILED(result.punkVal->QueryInterface(IID_IEnumVARIANT,(void
**) &m_FilesCollection)))
return E_INVALIDARG;
} else {
return E_INVALIDARG;
}
return S_OK;
}
I've passed in a collection with 200 IPictureDisp's in it, but the result
of that Invoke() is a vt of "Empty"
Ideas?
Rob