Re: How to handle classes in a ATL interface
Hello Igor,
I follow your tip to create two wrappers for Person and Company. Now I
can send ATL Objects from Visual Basic into my C++ project. But how
doese the way back work? I have a Company object in C++ with several
Persons. Now I want to send a person from C++ to Visual Basic.
This function should give a Person back:
STDMETHODIMP CAtlCompany::GetCustomer(IAtlPerson** Customer) {
CAtlPerson *oAtlPerson=0; // CAtlPerson is the wrapper for CPerson
oAtlPerson = new CAtlPerson(); // Create a new Wrapper.
CPerson oPerson=0; // This is the unchangeable C++ object.
oPerson = m_oCompany.GetPerson(); // Get the person from C++
oAtlPerson.SetObj(oPerson); // Fill the person into the Wrapper.
*Customer = oAtlPerson; // Return the wrapper.
return S_OK;
}
The problem is that CAtlPerson is abstract and cannot be instansiated.
The ATL part should allow this in VBA
Function TestAbc()
Dim Customer As Person
Dim MyCompany As Company
Call Customer.SetName("Emil Maier")
Call MyCompany.AddEmployee(Customer)
Customer = MyCompany.GetEmployee(1)
Debug.Print Customer.GetName()
End Function
This is the project with a Person and a company object:
http://freenet-homepage.de/kuh_an_wand/TestAtl.zip
In atlcompany.cpp is the broken code from GetCustomer.
Regards
Martin