Groups | Blog | Home
all groups > dotnet interop > october 2004 >

dotnet interop : COM Enumeration Interop Problem


James Hancock
10/29/2004 10:43:46 AM
Hey all. I have a problem with my implimentation of IHTMLElementCollection
which I have defined like so:

[ComVisible(true), Guid("3050f21f-98b5-11cf-bb82-00aa00bdce0b"),

InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch),

TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FDispatchable)]

public interface IHTMLElementCollection : IEnumerable{

[DispId(HTMLConsts.DISPID_IHTMLELEMENTCOLLECTION_TOSTRING)]

[return: MarshalAs(UnmanagedType.BStr)]

string ToString();

[DispId(HTMLConsts.DISPID_IHTMLELEMENTCOLLECTION_LENGTH)]

int Length {get;}

[DispId(HTMLConsts.DISPID_IHTMLELEMENTCOLLECTION__NEWENUM)]

[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef =
typeof(EnumeratorToEnumVariantMarshaler))]

new IEnumerator GetEnumerator();



[DispId(HTMLConsts.DISPID_IHTMLELEMENTCOLLECTION_ITEM)]

[return: MarshalAs(UnmanagedType.IDispatch)]

IHTMLElement Item([In] int Index);

[DispId(HTMLConsts.DISPID_IHTMLELEMENTCOLLECTION_ITEM)]

[return: MarshalAs(UnmanagedType.IDispatch)]

IHTMLElement Item([In, MarshalAs(UnmanagedType.BStr)] string Name);

[DispId(HTMLConsts.DISPID_IHTMLELEMENTCOLLECTION_TAGS)]

[return: MarshalAs(UnmanagedType.Interface)]

object Tags([In, MarshalAs(UnmanagedType.BStr)] string TagName);

}



The problem is that I end up with a non-trappable error (that just results
in termination of that function) when I try to access any of the Items or
the Enumerator itself.

Anyone have any ideas as to what I'm doing wrong?

Thanks!

James Hancock

James Hancock
10/29/2004 4:23:14 PM
Ok, thanks for your help!

What about this now:
[DispId(HTMLConsts.DISPID_IHTMLELEMENT_TAGNAME)]

string TagName{[return: MarshalAs(UnmanagedType.BStr)] get;}

I get the same sort of error when I do Element.TagName...

Thanks!

James Hancock



[quoted text, click to view]

Robert Jordan
10/29/2004 8:00:17 PM
Hi James,

[...]
[quoted text, click to view]

[...]
[quoted text, click to view]

You have 2 Items, both wrongly declared. Use that instead:

[DispId(HTMLConsts.DISPID_IHTMLELEMENTCOLLECTION_ITEM)]
[return: MarshalAs(UnmanagedType.IDispatch)]
IHTMLElement Item(
[In, Optional, MarshalAs(UnmanagedType.Struct)]
object name,
[In, Optional, MarshalAs(UnmanagedType.Struct)]
object index
);

bye
Robert Jordan
10/30/2004 2:40:35 PM
Hi James,

[quoted text, click to view]

Hmm, it looks ok to me. Please chech the order of the
members you declared. They must exactly match the
order of the IHTMLElement IDL.

bye
James Hancock
11/2/2004 1:06:24 PM
It looks like it still has something to do with the enumeration. Because if
I use the IHTMLElement definition outside the enumeration from another
source it's fine...

I'll check your suggestion.

[quoted text, click to view]

AddThis Social Bookmark Button