ATL NEWBEE

Hi, I was given the fallowing task:

1. Create an ATL COM project that inside uses another dll file.
2. Create a test project that tests the ATL COM component.
3. The ATL COM component should communicate with the other dll file using COM (it that means something to you pls explain)

For now, I managed to create ATL COM project and test console application with ATL support. I created myClass class in the ATL COM using the wizard(simple object class). I included the .lib in project properties and .h in the cpp file of the test application.

When I try to create instance of myClass:      myClass com = new myClass(); i get the unknown identifier error.

Please give me some guidance for this problem.
Thanks
LVL 3
DimkovAsked:
Who is Participating?
 
bijopuliConnect With a Mentor Commented:
You have to cast it back to your class at the time of invoking:

CComPtr<IUnknown> com;
hr = CoCreateInstance( CLSID_eVem, NULL,CLSCTX_INPROC_SERVER,CLSID_eVem, (void**) &com);
( (Your_Class_Name*) com )->SomeFunctionHere();
0
 
bijopuliCommented:
Hi
                                _________________                     _________________
  Instantiating         |                                 |                   |                                  |
  and calling   ------>| COM COMPONENT 1 |------------->| COM COMPONENT 2  |
  functions of           |________________ |                   |_________________|
  outer com                Outer Component                          Inner Component
  component

There are 2 re-usability models by which you can use one COM Component (dll file) from another COM component namely:

1)Containment - simply instantiate a com object in one component from the other component and use it. And the caller should expose the methods of the instatiated objects, or it can simply use it.

2)Aggregation - This is a re-usability model by which a COM component is made to behave exactly like the instantiated object with added functionality introduced by the Outer Component.

Here are some articles which will throw some light into your problem:

Genaral Article:
http://www.codeproject.com/atl/Reusing_COM_objects-Part1.asp

Containment :
http://www.codeproject.com/com/ComContainment.asp

Aggregation :
http://www.codeproject.com/com/unleashingaggregation.asp


Regards
Bijo.
0
 
DimkovAuthor Commented:
Bijo thank you for your input. I will give a good look at the links
What hurts me the most is: A cant use the class I created in Com component1 :(
I added a class there myClass with function myFunction. But I can't make an instance of it in my test app nor call the function. It must be something very easy, but I cant find a way nowhere on internet.

At this moment I am looking on something like CoCreateInstance,
but it would be great If I can do something more like:

myClass com = new myClass();
com.myFunction();

is this possible?


0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
DimkovAuthor Commented:
I managed to add simple function, but  I still can add a class...

  IeVem *IFirstATL=NULL;
  CoInitialize(NULL);
  CComPtr<IeVem> com;
  hr = CoCreateInstance( CLSID_eVem, NULL,CLSCTX_INPROC_SERVER,IID_IeVem, (void**) &IFirstATL);
  IFirstATL->SomeFunctionHere()      
0
 
bijopuliCommented:
Try this:

  CComPtr<Replace this by ur Class Name> com;
  hr = CoCreateInstance( CLSID_eVem, NULL,CLSCTX_INPROC_SERVER,CLSID_eVem, (void**) &com);
0
 
DimkovAuthor Commented:
it doesn't recognize it. Unknown identifier
0
 
DimkovAuthor Commented:
is exporting class possible? if not a struct maybe?
0
 
bijopuliCommented:
i am sorry there is a correction:

U have to use the IUnknown pointer to instantiate a class class,
IUnknown is the base interface from which all COM classes are derived from.

Please try this:

CComPtr<IUnknown> com;
hr = CoCreateInstance( CLSID_eVem, NULL,CLSCTX_INPROC_SERVER,CLSID_eVem, (void**) &com);

0
 
DimkovAuthor Commented:
how will I be then able to call the function?
0
 
DimkovAuthor Commented:
that is my problem: the application does not recognize the class. It is called myClass and it is generated by the ATL wizard. But still, I can make the test app recognize it

When using  ( (myClass*) com )->SomeFunctionHere(); - i get unknown identifier error.
0
 
bijopuliConnect With a Mentor Commented:
Hi

I was out for a few days..

Can u show me your IDL code?

Regards
Bijo.
0
 
DimkovAuthor Commented:
Hi Bijo,
higher priority task was given to me, and I will have to finish that first
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.