I've just changed:
[propget, id(DISPID_VALUE), helpstring("property Item")]
HRESULT Item([in] VARIANT* Index, [out, retval] LPDISPATCH* punk);
to:
[propget, id(DISPID_VALUE), helpstring("property Item")]
HRESULT Item([in] VARIANT Index, [out, retval] IChain** ppChain);
Thanks for your suggestion. Changing VARIANT* to VARIANT fixes the
problem - i.e. the [] syntax works correctly. C# doesn't seem to cope with
the [] syntax when passing the index by reference, which could be a problem
with other collections. :-(
Next problem, is that I can now access the objects using collection["key"],
but if I use collection[1] I get a stack overflow. It works fine in VBA.
Thanks,
Aaron Queenan.
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:%2***************@TK2MSFTNGP12.phx.gbl...
Aaron,
You should be able to use the square brackets to access the
information. However, you will still have to pass it as an object reference.
You could change the IDL so that it takes a variant by value (remove
the pointer), but then you would have to change the underlying implementation
as well. If you change it so that it takes a string (change Variant to BSTR)
then you will not have the ability to access the items by index.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"Aaron Queenan" <aq*********************@contingent.com.au> wrote in
message news:Oy**************@TK2MSFTNGP12.phx.gbl... I have the following in the idl for a COM collection:
[propget, id(DISPID_VALUE), helpstring("property Item")] HRESULT
Item([in] VARIANT* Index, [out, retval] LPDISPATCH* punk);
This allows VBA to access objects in the collection using the syntax
collection("key") or collection(1).
When I import this type library into C#, the DISPID_VALUE property
appears as 'this[]', and when I try to use the syntax similar to VBA, the
compiler complains that I must use collection.get_Item() instead of collection().
1. How should I form the idl so that I can use the collection.Item[]
syntax, as I would be able to if I didn't use DISPID_VALUE?
2. If I use the collection.get_Item() syntax, I must convert the
Index parameter to an 'object ref', and the method returns an object. How
should I change the idl so that the method accepts a 'string' and returns the
correct object type?
Thanks,
Aaron Queenan.