Re: How to handle classes in a ATL interface
Martin.Salo@gmx.net wrote:
I have two classes: Person and Company. I want to export this Objects
via Com/Atl to Excel VBA. The class Person has only string attributes.
(SetName/GetName, SetAddress/GetAddress, ...)
My problem: The Company has additional a method "AddCustomer(Person
*Customer)". What is the standard method to exchange a class through
the Atl interface?
COM doesn't know anything about classes. COM only deals with interfaces.
You would define two interfaces, IPerson and ICompany. You would have
Person and Company implement these interfaces, or wrap them in COM
objects that implement these interfaces. ICompany interface would have a
method AddCustomer([in] IPerson*)
(I can use the Interface of Person as a parameter,
but how can I get the Person object behind the interface from the
interface?)
While there are ways, they are somewhat fragile. It is usually better to
change the design so that you don't have to. For exampe, AddCustomer
could be a factory method - instead of taking a Person object, it would
create and return a new one. The client would do something like
dim p
p = c.AddPerson ' c refers to Company object
p.name = "Martin"
....
Do I have a chance to get the coclass of Person into the method
parameter list?
No.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925