Link to home
Start Free TrialLog in
Avatar of mflam
mflam

asked on

Easiest way to make ATL Simple Objects: aggragatable + aggragating & test them.

I'm looking for a tutorial or if anybody can tell me:
How do I make a project with two combined objects: one aggregating and one aggregatable.
I'm looking to use as few as possible code inside, mostly the menu's wizards and helper functions.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mflam
mflam

ASKER

Hello chensu,

I'm not sure I understood correctly:
1. Is this what I should do?:
In ATL I make a simple object and checked the ONLY for aggravation.
The object is an elephant's trunk, called "TrunkObj", with a method called "spritz()".

Now to aggregate the TrunkObj into my elephant obj, I create a simple ATL object called "ElephantObj".
Then follow the instructions in the MSDN tut you pointed me to?

2. Will doing this cause the following?
A. I will not be able to call myTrunk.spritz. (Say in Visual Basic)?
B. I will be able to make an Elephant.Spritz() method, that will call the m_Trunk.Spritz()? or...

C. I don't understand aggregation, and the concept is something else? (which is?)

3. Last question: Is this the easiest way in VC++6, or is there some clickable menu/wizard/popup somewhere that will do this automatically for me?

Thanks!

1. If you choose ONLY, the object can be used ONLY thru aggregation.

2. That is containment instead of aggregation. See

http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/devprods/vs6/visualc/vcmfc/_atl_aggregation.htm

3. Why does Microsoft documentation tell you a harder way if there is an easier way?
I think it will be difficult for
you to implement the object
(at least professionally) without
some basic understanding of aggregation.

Your question is not very clear to me.
Can u elaborate more.
Avatar of mflam

ASKER

Chensu, thanks.
Could you post a peace of code with an actual aggragate. (Not everything is there in the example, and the sample has too much.)

About my "easiest way" question: MSDN has tons of info, from older versions, and some very detailed examples. They  don't always show the easiest way.
Even in THIS example:
1. They did not show how to release the aggragate, just said where to do it.
2. They used CoCreateInstance and not an ATL smartpointer.
3. I'm still not sure there is no "Add New ATL Class" trick that will add everything automatically.

Thanks again, Moshe
Avatar of mflam

ASKER

Basant hello,

I wanted to be sure I understood correctly. I have the answer to that, it's yes.
My questions are now practical:
1. I would like to see a few peaces of code completely covering the aggravation.
2. I would like to know if (despite the MSDN) there is some button that would do most of it or all of it automatically. (Like the "implement connection point").

I will consider any of these 2 as an answer. preferebly both (and added 50 points)

Moshe
I have code written in Win32 which
shows aggregation. If u want I can
mail it to you. You can give ur mail
id to me.

In ATL what I know is you only
specify a MACRO to allow the
object to support AGGREGATION
but in Win32 you actually do it urself.
It also took me some time to understand
those concepts.

The following KB article shows you how to aggregate a COM object in an ATL project.

HOWTO: Aggregate a COM Object with ATL
http://support.microsoft.com/support/kb/articles/Q173/8/23.ASP
Avatar of mflam

ASKER

Thank you!
I now have 900 expert points and only 50 regular. How do I get more points for regular questions?
Avatar of mflam

ASKER

Basant hello,

I completely understand the Win32 C COM aggragation. In fact, I even have objects written using it.
I wanted:
1. To be sure I understood correctly. (which apparently I did).
2. I wanted ATL code.

Thank you for your comments.

Moshe
>How do I get more points for regular questions?

It increases by 5 points every day as long as you keep active.
Avatar of mflam

ASKER

Wait! I now have a last question for this line.
I want to use smartpointers instead of the CoCreateInstance of the example.
I #import the AggObj.DLL and include it's AggObj_i.c file.
BUT:
1. Do I call CoInitialize(NULL); ?
2. Do I call the m_pAgg->Release();
in the FinalRelease() ?

Thanks...
Avatar of mflam

ASKER

I also did not undersand you answer about points.
I need another 100 points for an important question.
How do I get them?
(I cannot wait so many days...)

Moshe
>1. Do I call CoInitialize(NULL); ?

Yes, you need to call it and CoUnintialize() in the end.

>2. Do I call the m_pAgg->Release();
in the FinalRelease() ?

If m_pAgg is a smart pointer, you don't have to call it.

>I need another 100 points for an important question. How do I get them?

Wait or click the More Points! link at the bottom of the page.

https://www.experts-exchange.com/secure/bin/MorePoints
Dear mflam

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "chensu"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: https://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
Per recommendation, force-accepted by
Netminder
CS Moderator