Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to call not a default constructor in COM Server?

Posted on 2001-09-14
5
Medium Priority
?
295 Views
Last Modified: 2013-11-25
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
0
Comment
Question by:krassiB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
jtm111 earned 800 total points
ID: 6484127
I am not an expert in ATL COM, but I have come upon the same problem.

Can't you just use the default constructor for purposes of CoCreateInstance (it doesn't even have to do anything other than create an instance of your interface), but define a method X for your interface that takes VARIANT, BSTR, arguments, etc, and have method X call your class constructor with arguments?


Maybe I misunderstand your problem.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6484130
What if you made your own constructor to override the default constructor or the constructor with the parameter?

Can you sub-class the class and give the constructor a default parameter?

This assumes you are doing some C++ compiling.

0
 
LVL 30

Expert Comment

by:Axter
ID: 6484152
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?
0
 

Author Comment

by:krassiB
ID: 6484178
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
0
 

Author Comment

by:krassiB
ID: 6484276
See my previous comments
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question