Re: ATL/COM memory management
From: Jag Man (Jag_Man653R-E-MOVE_at_hotmail.com)
Date: 05/10/04
- Previous message: Doug Harrison [MVP]: "Re: Are the but standard C++ functions such as itoa(int,char*) supported or not???"
- In reply to: Simon Trew: "Re: ATL/COM memory management"
- Next in thread: Simon Trew: "Re: ATL/COM memory management"
- Reply: Simon Trew: "Re: ATL/COM memory management"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 10 May 2004 08:40:45 -0700
Simon,
> > Dim myObj As myClass(10)
> > in the declarations section of a Module, but it is not accepted.
>
> No, the client will create ten instances of the object by making ten calls
> to the class factory.
I was not trying to indicate 10 instances of the class. Rather, I was trying
to say
one instance of the class, but with that instance having a member array
allocated
to be size 10.
> > If it can't be done this way, how does one get the size to allocate some
> > form of an array
> > in a constructor or FinalConstruct()?
>
> I'm not sure what you are trying to do here. The array (or a
> pointer/reference to it) should be a *member* of the coclass, which then
> defines indexed properties to access it.
>If desirable, make a separate
> "container" class that just wraps the array, and in your other class
define
> properties which are typed to this separate class. (This also has the
> advantage that the separate class is likely to me more reusable, and then
> you can also define the NewEnum property on it to get "for each" style
> enumeration.
Yes, the array is to be a class member. Clearly, that array has to have
memory allocated
for it. In C++ one would make the class member a pointer, then allocate in
the constructor
using a parameter:
myClass::myClass(int size)
{
n = size;
theArray = new long[n];
}
so that to instantiate one would write:
myClass object(10); // creating one instance of myClass having an array size
of 10.
I am trying to do the equivalent of this in a COM to be used in VBA. What I
am missing somehow
is how the VBA tells the COM what size of array will be needed.
Thanks for your patience!
Ed
- Previous message: Doug Harrison [MVP]: "Re: Are the but standard C++ functions such as itoa(int,char*) supported or not???"
- In reply to: Simon Trew: "Re: ATL/COM memory management"
- Next in thread: Simon Trew: "Re: ATL/COM memory management"
- Reply: Simon Trew: "Re: ATL/COM memory management"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|