Link to home
Create AccountLog in
Avatar of Dimkov
Dimkov

asked on

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
Avatar of bijopuli
bijopuli
Flag of India image

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.
Avatar of Dimkov
Dimkov

ASKER

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?


Avatar of Dimkov

ASKER

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()      
Try this:

  CComPtr<Replace this by ur Class Name> com;
  hr = CoCreateInstance( CLSID_eVem, NULL,CLSCTX_INPROC_SERVER,CLSID_eVem, (void**) &com);
Avatar of Dimkov

ASKER

it doesn't recognize it. Unknown identifier
Avatar of Dimkov

ASKER

is exporting class possible? if not a struct maybe?
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);

Avatar of Dimkov

ASKER

how will I be then able to call the function?
ASKER CERTIFIED SOLUTION
Avatar of bijopuli
bijopuli
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Dimkov

ASKER

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.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Dimkov

ASKER

Hi Bijo,
higher priority task was given to me, and I will have to finish that first