Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ATL NEWBEE

Posted on 2007-10-01
12
Medium Priority
?
219 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
0
Comment
Question by:Dimkov
  • 7
  • 5
12 Comments
 
LVL 6

Expert Comment

by:bijopuli
ID: 19989775
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
 
LVL 3

Author Comment

by:Dimkov
ID: 19989789
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
 
LVL 3

Author Comment

by:Dimkov
ID: 19989852
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 6

Expert Comment

by:bijopuli
ID: 19989979
Try this:

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

Author Comment

by:Dimkov
ID: 19990020
it doesn't recognize it. Unknown identifier
0
 
LVL 3

Author Comment

by:Dimkov
ID: 19990024
is exporting class possible? if not a struct maybe?
0
 
LVL 6

Expert Comment

by:bijopuli
ID: 19990069
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
 
LVL 3

Author Comment

by:Dimkov
ID: 19990081
how will I be then able to call the function?
0
 
LVL 6

Accepted Solution

by:
bijopuli earned 2000 total points
ID: 19990099
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
 
LVL 3

Author Comment

by:Dimkov
ID: 19990131
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
 
LVL 6

Assisted Solution

by:bijopuli
bijopuli earned 2000 total points
ID: 20013529
Hi

I was out for a few days..

Can u show me your IDL code?

Regards
Bijo.
0
 
LVL 3

Author Comment

by:Dimkov
ID: 20027272
Hi Bijo,
higher priority task was given to me, and I will have to finish that first
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question