Groups | Blog | Home
all groups > dotnet interop > september 2005 >

dotnet interop : hiding System.Object from COM ??



Robert Jordan
9/20/2005 12:00:00 AM
[quoted text, click to view]

Use ClassInterfaceType.AutoDispatch.

Robert Jordan
9/20/2005 12:00:00 AM
[quoted text, click to view]

Yes. Now I unterstand what you want to achieve.

You have to define an interface with the methods you want to
expose and let your class implement that interface.
In this case you have to use ClassInterfaceType.None.

emma_middlebrook NO[at]SPAM fastmail.fm
9/20/2005 7:07:23 AM
Hi

I'm exposing a simple VB.NET object for use by COM.

If I expose the class using the following attribute

System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual)>

then in the .tlb file I get all the System.Object methods ...

Any ideas how I can suppress this easily please?

Cheers

Emma Middlebrook


interface _Exposed : IDispatch {
[id(00000000), propget,
custom({54FC8F55-38DE-4703-9C4E-250351302B1C}, "1")]
HRESULT ToString([out, retval] BSTR* pRetVal);
[id(0x60020001)]
HRESULT Equals(
[in] VARIANT obj,
[out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020002)]
HRESULT GetHashCode([out, retval] long* pRetVal);
[id(0x60020003)]
HRESULT GetType([out, retval] _Type** pRetVal);
};
emma_middlebrook NO[at]SPAM fastmail.fm
9/20/2005 7:24:17 AM
Thanks very much for your reply but I would really like the members to
be visible. Rather than going through all the hassle of GetIDsOfNames
and Invoke and so on!

If I understand correctly AutoDispatch will mean I can no longer see
anything for early binding purposes.

Is that true?

Emma
emma_middlebrook NO[at]SPAM fastmail.fm
9/20/2005 11:39:31 AM
[quoted text, click to view]

Robert

Thanks very much for your reply again and sorry I didn't make myself
properly clear before. I did read MSDN and so roughly tried to do what
you suggest i.e. I got the class to implement an interface that I
wished to expose (without System.Object stuff) and tried it out. It
didn't seem to work but thinking about it, it might be because I didn't
explicitly use None thinking that it might be the default. Am at home
now but will have another look tomorrow!

Thanks for you help

Emma
emma_middlebrook NO[at]SPAM fastmail.fm
9/21/2005 2:30:10 AM
Hi

Your advice worked perfectly. Thankyou. I now have my class as follows
in the type library:

coclass DistributionFactory {
interface _Object;
[default] interface IDistributionFactory;
};

Now I have two further questions!

1. Is there a way to remove the superfluous (for us) _Object interface?

2. Would anyone be able to suggest a reason why unmanaged code would
ever want to make use of that interface?

Many thanks to the newsrgoup!

Emma
AddThis Social Bookmark Button