>>>Making the default ctor internal has the effect I want for COM clients by
>>>making the coclass noncreatable in the generated TLB.
[quoted text clipped - 10 lines]
>>be created for that class. W/Out the CCW there is no way to access
>>the object from COM.
Correction: the CCW gets created for ComVisible(false) as well.
> But I *can* access it with ComVisible = false, via the ICustomer interface.
> I can do everything with it I want except iterate using For Each.
The problem is the automatic managed IEnumVARIANT wrapper that
probably checks the ComVisible flag of the items.
You can make the Customer class noncreatable by removing
its registry entries during the COM registration.
See the ComRegisterFunctionAttribute class docs.
Rob
Joe - 11 Sep 2005 19:09 GMT
Rob, thanks again.
> The problem is the automatic managed IEnumVARIANT wrapper that
> probably checks the ComVisible flag of the items.
So is this a bug in the IEnumVARIANT wrapper, or is it by design? If it is
by design, what is the justification for this strange design? .NET 2.0 Beta
2 has the same behaviour: should I raise a bug on the feedback center?
> You can make the Customer class noncreatable by removing
> its registry entries during the COM registration.
>
> See the ComRegisterFunctionAttribute class docs.
That's an interesting, if rather kludgey workaround. I'll investigate this
week.
> Rob
Robert Jordan - 11 Sep 2005 20:16 GMT
Hi Joe,
>>The problem is the automatic managed IEnumVARIANT wrapper that
>>probably checks the ComVisible flag of the items.
>
> So is this a bug in the IEnumVARIANT wrapper, or is it by design? If it is
> by design, what is the justification for this strange design? .NET 2.0 Beta
> 2 has the same behaviour: should I raise a bug on the feedback center?
I'm not sure whether it's a bug. The doc of ComVisibleAttribute
states that a object whose type has ComVisible(false) won't
respond to QueryInterface. So I don't unterstand why you can
access a Customer object at all.
By any chance, can you clean up the registry and retry?
Or change the GUID of the Customer class? I'm supposing,
that your Customer is still registered with COM.
Rob
Joe - 13 Sep 2005 07:40 GMT
> I'm not sure whether it's a bug. The doc of ComVisibleAttribute
> states that a object whose type has ComVisible(false) won't
[quoted text clipped - 4 lines]
> Or change the GUID of the Customer class? I'm supposing,
> that your Customer is still registered with COM.
That's an excellent suggestion, I hadn't thought of that. However, having
cleaned the registry, then rebuilt the project with ComVisible=false for the
Customer class, I am still getting the same behaviour:
- I can access the Customer object from VB6 via the ICustomer interface
without any problems. For example, the following VB6 code works fine:
Dim col As CustomerCollection
Dim c As ICustomer
Set col = New CustomerCollection
Set c = col(1)
Debug.Print c.Name
- But I still can't iterate through the CustomerCollection using For Each
I think I'll raise a bug oin the product feedback center and see if they can
throw any light on this behaviour.