ATL question

G

Grey Alien

might be slightly OT...

I am writing a wrapper (ATL) COM class around a C++ class. The C++ class
does not have a default ctor - The ctor requires various arguments to be
passed to it - one of which is a C++ reference.

How may I pass the arguments to the ATL ctor?
 
J

Johannes Passing

COM (and thus ATL) does not support constructors with arguments. You
basically have 3 options:
* Include an initialize-method in your interface that takes the
initialization arguments you would otherwise have passed to the
constructor. Of course, your object is in a dubious state between beeing
constructed and the initialize-method being called.
* Let DllGetClassObject not return an IClassFactory but a custom
interface that allows arguments to be passed to its equivalent of
CreateInstance(). However, your object will not be able to be created by
CoCreateInstance and neither by VB, .Net etc as they all rely on
IClassFactory being implemented.
* Make your object 'private', i.e. not createable for external clients
and provide an additional (public) factory class that provides a method
that takes all your arguments, creates an instance of the private
object, initializes it (through some non-public interface) and returns it.

--Johannes
 
G

Grey Alien

Johannes said:
COM (and thus ATL) does not support constructors with arguments. You
basically have 3 options:
* Include an initialize-method in your interface that takes the
initialization arguments you would otherwise have passed to the
constructor. Of course, your object is in a dubious state between beeing
constructed and the initialize-method being called.
* Let DllGetClassObject not return an IClassFactory but a custom
interface that allows arguments to be passed to its equivalent of
CreateInstance(). However, your object will not be able to be created by
CoCreateInstance and neither by VB, .Net etc as they all rely on
IClassFactory being implemented.
* Make your object 'private', i.e. not createable for external clients
and provide an additional (public) factory class that provides a method
that takes all your arguments, creates an instance of the private
object, initializes it (through some non-public interface) and returns it.

--Johannes

Thanks for the clarification Johannes. I may contact you on your hotmail
address if I get stuck (I hope you don't mind)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top