Single / Multiple ATL COM object instances (using smartpointer)

Help! Please! Partial answer will get points too!
I am using the smartpointer recieved from the #import directive in the client.
My objects are ATL simple objects.

I would like to understand how to make multiple/single instances of objects:

1. If I wish to make only ONE instance called from several clients:
1.1 How do I do it without modifying the code of my object (if possible)?
1.2 What can I modify in the object so it's always one instance that comes up?
1.3 What happens if I use such a "singelton" in MTS?

2. If I want multiple instances of the same object in each client:
2.1 How do I do it without modifying the code of my object (if possible)?
2.2 What can I modify in the object so it's always one instance per client
(if possible at all)?
2.3 What happens if I use such a "forced multipleton" in MTS?
LVL 2
mflamAsked:
Who is Participating?
 
ajitmConnect With a Mentor Commented:
You can use one smart pointer as a member in the client. Take only one instance of the object by calling 'new'.

e.g. IYourClassPtr pTempPtr;

pTempPtr = new IYourClassPtr(__uuidof(YourClass));

Then afterwords use only the smart pointer i.e. IYourClassPtr .

I think this will ensure single instance of the class per client.

Hope this will work.

Ajitm
0
 
mflamAuthor Commented:
Adjusted points to 100
0
 
mflamAuthor Commented:
Edited text of question.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mflamAuthor Commented:
Help! Please.
0
 
mflamAuthor Commented:
Please! Urgent!
0
 
mflamAuthor Commented:
Adjusted points to 120
0
 
mflamAuthor Commented:
Edited text of question.
0
 
mflamAuthor Commented:
Edited text of question.
0
 
mflamAuthor Commented:
I found out also that I can use the:

DECLARE_CLASSFACTORY_SINGLETON

for making the smartpointer singelton always. (in other words for making a single shared object).

Otherwise I get a new object for each call.

Thank you very much, Moshe
0
 
ajitmCommented:
Hi mflam,
You have accepted the answer but no points are added to me(120 pts.). Please do the needful.
Thanks.
Ajitm.
0
All Courses

From novice to tech pro — start learning today.