Connecting Tech Pros Worldwide Forums | Help | Site Map

ATL question

Grey Alien
Guest
 
Posts: n/a
#1: Jul 27 '07
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?

Johannes Passing
Guest
 
Posts: n/a
#2: Jul 27 '07

re: ATL question


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

Grey Alien wrote:
Quote:
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?

--
Johannes Passing - http://int3.de/
Grey Alien
Guest
 
Posts: n/a
#3: Jul 27 '07

re: ATL question



Quote:
Grey Alien wrote:
>
Quote:
>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?
>
>
>
Johannes Passing wrote:
Quote:
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.
Quote:
>
--Johannes
>
Thanks for the clarification Johannes. I may contact you on your hotmail
address if I get stuck (I hope you don't mind)
Closed Thread