krassiB
asked on
How to call not a default constructor in COM Server?
Hi Guys,
I have a COM server, written in C++ using ATL in VStudio.
I have another class (in separate DLL) that I am using from COM DLL. The other class has two constructors: one the default and the other with one parameter.
ATL Wizard generates just one constructor for the class implementing COM.
I am creating a object from VB client with CreateObject function, but this function does not accept parameters as in C++ (so I can pass my parameter and initalize the second constructor).
Thanks for the help,
Krassi
I have a COM server, written in C++ using ATL in VStudio.
I have another class (in separate DLL) that I am using from COM DLL. The other class has two constructors: one the default and the other with one parameter.
ATL Wizard generates just one constructor for the class implementing COM.
I am creating a object from VB client with CreateObject function, but this function does not accept parameters as in C++ (so I can pass my parameter and initalize the second constructor).
Thanks for the help,
Krassi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Are you creating the object in the VB side, or the VC++ side?
Can you show some of your code?
Can you post the declaration for your class?
Can you show some of your code?
Can you post the declaration for your class?
ASKER
jtm111,
you understood very well my question.
And this is what I did. And it works.
You deserve to receive the points.
I was thinking may be there is more sofisiticated
way to solve the problem.
Triskelion,
what do you mean to create my own constructor?
Please explain.
Axter,
I am instantiating the object in VB side (this is the client). I have also C++ class library, which I have done.
The task is to wrap it up for use with COM (for easy use from VB). So I started to implement the COM interfaces in C++ using ATL.
In my original library let say I have class
SampleClass, wich has default constructor SampleClass()
and the second one SampleClass(int x).
When I create ATL Class implementing COM interface it has just default constructor (created by the Wizard), which is invoked by CreateObject function in VB, which is used for instanciating COM object. The problem is that you can not pass to CreateObject more parameters, needed for the other constructor (in my case just one). That is way as per jtm111 suggestion you need to create another interface method with one parameter. If you have more constructors you should implement as many such methods as constructors you have in the original one.
If somebody has any other idea, please let me know.
Thanks for your time and help!
Krassi
you understood very well my question.
And this is what I did. And it works.
You deserve to receive the points.
I was thinking may be there is more sofisiticated
way to solve the problem.
Triskelion,
what do you mean to create my own constructor?
Please explain.
Axter,
I am instantiating the object in VB side (this is the client). I have also C++ class library, which I have done.
The task is to wrap it up for use with COM (for easy use from VB). So I started to implement the COM interfaces in C++ using ATL.
In my original library let say I have class
SampleClass, wich has default constructor SampleClass()
and the second one SampleClass(int x).
When I create ATL Class implementing COM interface it has just default constructor (created by the Wizard), which is invoked by CreateObject function in VB, which is used for instanciating COM object. The problem is that you can not pass to CreateObject more parameters, needed for the other constructor (in my case just one). That is way as per jtm111 suggestion you need to create another interface method with one parameter. If you have more constructors you should implement as many such methods as constructors you have in the original one.
If somebody has any other idea, please let me know.
Thanks for your time and help!
Krassi
ASKER
See my previous comments
Can you sub-class the class and give the constructor a default parameter?
This assumes you are doing some C++ compiling.