We help IT Professionals succeed at work.

ATL NEWBEE

Dimkov
Dimkov asked
on
233 Views
Last Modified: 2013-11-25
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
Comment
Watch Question

bijopuliSoftware Architect

Commented:
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.

Author

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?


Author

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()      
bijopuliSoftware Architect

Commented:
Try this:

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

Author

Commented:
it doesn't recognize it. Unknown identifier

Author

Commented:
is exporting class possible? if not a struct maybe?
bijopuliSoftware Architect

Commented:
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);

Author

Commented:
how will I be then able to call the function?
Software Architect
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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.
bijopuliSoftware Architect
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi Bijo,
higher priority task was given to me, and I will have to finish that first
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.