Re: Using CoCreateInstance in COM Aggregation?
Donos <donguy76@gmail.com> wrote:
Inside the FinalConstruct of CommonCoClass, i have used the following
code,
hr = CMyInterface::_CreatorClass::CreateInstance(
GetControllingUnknown(), __uuidof(IMyInterface),
(void**)&m_pInnerMyInterface);
One doubt i have is whether GetControllingUnknown() will do the magic
of getting the IUnknown pointer to Outer object?
Yes. GetControllingUnknown returns your own IUnknown pointer, unless
your object is itself aggregated in which case it returns your outer
unknown (each object in an aggregation chain should refer to the
outer-most object as its outer).
Now am trying to get the interface pointer to IMyInterface from
Client.
For that i used the following code,
HRESULT hr = CoCreateInstance(CLSID_CommonCoClass, NULL,
CLSCTX_INPROC_SERVER,__uuidof(IMyInterface), (LPVOID*)&pMyInterface);
This is not working.
Did you list IMyInterface in CommonCoClass' interface map? See
COM_INTERFACE_ENTRY_AGGREGATE
But now i understand that as the IMyInterface is aggregated inside
CommonCoClass, i need to pass the Outer IUnknown pointer as 2nd
parameter here.
No, you don't. The client isn't aggregating anything.
--
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