Re: Instantiating ComObjects - best practice
"Alexander Lamaison" <email@example.com> wrote in message
On Sat, 26 Jul 2008 10:59:37 -0400, Igor Tandetnik wrote:
Of course, you don't have to "litter" your code with this. Write a
static CMyObject::MakeInstance function that does all this and
returns a properly AddRef'ed interface pointer.
Ok. Thanks. I wasn't sure you were allowed to do this. I'm a little
hazy on what can be called safely in a standard C++ way (i.e. not
through a COM interface) on an ATL object.
An ATL object is a C++ class like any other. There's no black magic
I've seen people passing 'this' to methods that require an interface
pointer that the object supports, without doing a QueryInterface?
A COM interface is just an abstract C++ class. Your ATL class derives
from it. As usual, you can pass a pointer to derived class wherever a
pointer to base class is needed.
How do you make an object non-creatable?
You don't mention it in IDL, don't derive it from CComCoClass, don't
list it in object map (omit OBJECT_ENTRY[_AUTO] for it) and don't
register it (remove all references to it, if any, from .RGS files).
In other words, all objects are non-creatable until you _do_ all of the
above to make one creatable.
With best wishes,
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