
Using a UDT in a Class method, how to make a class module public
John, thanks, some replies inline..
Quote:
> An class module is an object module (as opposed to a standard .bas module
which
> is not). Whether it is Public or Private depends on its Instancing
property.
> In a standard EXE you are not aware that a class has an Instancing
property
> because it is always Private, which means that you cannot create an
instance of
> the class from another project/component. Since it cannot be changed it
does
> not show up as a property in the properties window.
> If, however, you create an ActiveX DLL project you will see that the
default
> Class1 does have an Instancing property, and that that default is
MultiUse. One
> of the Instancing values you may select is Private. The others, including
> MultiUse, are all "public".
> So... If you:
> - define your UDT in the default Class1 of an ActiveX DLL (which is a
Public
> Object Module),
> - remove the UDT definition from your standard EXE,
> - reference the DLL in your standard EXE,
> then you are in business!! You do not even need to create an instance of
the
> Class1 in the DLL.
Ok, I get it. But then I'd rather just write my structures/UDT's in IDL and
reference the small resultant typelib.
Quote:
> That said, it is much easier to use Friend. Why does this work? I
haven't a
> clue. I have never seen an explanation to this one.
I'm quite new at VB (coming from a C background). My - confused - image is
sofar something like this:
(And I'm propably wrong somewhere..)
1. VB class methods that use UDT's are not supported by Automation (through
IDispatch).
2. Using Friend (vs. Public) will not inculde these methods in at least the
dispatchinterface (but perhaps in the vtable interface??)
3. Since a 'normal' (non-com/activex) VB class module is at runtime
implemented as a COM component (with a dual itf?), the Friend modifier
allows the methods to work.
I'd be very grateful if someone could shed some light on this for me.
I remember reading in 'Essential COM' that at the present time (VB6 I
assume), VB can *use* structs (e.g. UDTs) from a typelib when using a COM
server, but *cannot* be used to build COM servers that use (VB-defined)
UDT's as method parameters.
Quote:
> What is the difference between Public and Friend in a standard EXE? Well,
you
> can pass UDTs with Friend but not with Public!! Why? See above!!
With above said, I'd love to be proven wrong. If someone could post a (very
small) VB6 COM (ActiveX) DLL that uses UDT's in it's public methods (when
using early binding), or explain why such a thing is impossible, I'd be
grateful.
Regards,
Taras