You have copied DOn Box's book and you skip important questions. For example when you say
The outer object's QueryInterface. When queried for IVehicle, we delegate to the inner object's interface. However, remember that m_pUnknownInner is a pointer to the inner object's Non-Delegating INDUnknown (which doesn't have a QueryInterface method - so how does this work?)
You never explained why does the QI work in that case?
First I would like to thank Andrew.
You really write a good article!
After I have finished my work in aggregation ,I write
this two things for those whose still have problem in
COM and VB-based Client programming.
These two things are:
1.COM Component (VC.NET+ATL7.0)
Hope they are somewhat helpful for you.
(For I don't know how to add a attachment.Anyone Who wants it,please write to me!)
Lol. I wonder if anyone actually did this (no doubt they skipped ahead to the ATL versions). At any rate it doesn't work for a few somewhat interesting reasons.
A few bugs here (Visual C++ 6 sp 5). Simply importing the type library doesn't necessarily define the CLSID. So this won't compile, it will say "CLSID..." not defined. However a smart person would then add:
to solve this problem. Okay so far. Compiles okay. However note than when the variable "pv" goes out of scope at the end of the win32 app dynamically releasing the smart pointer causes an Access Error. This is an error on the dynamic release when called in this kind of environment. There doesn't appear to be a workaround as far as I can tell. If you call pv->Release() explicitly it still causes an Access Error.
The only thing that possibly makes sense here is that perhaps you shouldn't use smart pointers in a non-ATL app. Comments here?!?
Anyway you were probably in a hurry and thinking ATL where smart pointers are handled a bit better. If anyone is interested the non-smart pointer version in a win32 app that runs without that Access Error would look like this:
// don't define type library, use the raw _i.h with _i.c
IComSocket *pv = NULL;
// create the raw interface
HRESULT hr = CoCreateInstance( CLSID_Vehicle,
After reading this tutorial I was just trying to inherit MSXML object using either containment or aggregation. I understand the general concept for both of these. What I am expecting to achieve is, trying to provide a wrapper for MSXML object from c++ and then use this wrapper object in VB. The reason for me to doing this is the MSXML object has a property datatype with the let property signature accepting string type parameter but the get property signature returns variant. In VB the object can not be created or implemented with different property definitions such as string for Let and variant for get.
The object I want to create in C++ will just override this property, but should maintain rest all interfaces for IXMLDOMNODE of msxml3 or msxml4. Can you please help me directing to the right and easy approach (containment/aggregation) to accomplish this.