Vedran211

Hi,

I was given an IDL file and was asked to implement it.

How can I create a Project with VS2005, load the IDL somehow and let VS2005 generate the classes with empty methods.

After that I just have to implement each method.

That should actually be possible, because all the information about the classes already exists in the IDL-file, right

Can somebody help me or give me a hint

Thanks,
Vedran





Re: Visual C++ General VS2005 Implement an existing IDL

Sdi

1) Add the .IDL file to the project and build it to create the .TLB file.

2) Use the wizard to add a new "ATL Simple object" class.

3) Select the new class in Class View, right-click, Add, Implement Interface..., select File, and point to the .TLB





Re: Visual C++ General VS2005 Implement an existing IDL

Vedran Bratic

Thanks, but I would need it step by step. I already tried a lot but i dont get the right way...

1) I created a ATL project
2) I copy/pasted all from my given IDL file to the projects IDL (exept the library uuid)
3) Then I compiled the idl... I got a .h file with all the interfaces and virtual classes...

Should I now create an "ATL Simple object" for each class I would like to implement
and implement the interface

is this the right way to do it i just dont get it...

thanks
vedran






Re: Visual C++ General VS2005 Implement an existing IDL

Sdi

You could at least try the steps provided. The key pieces are generating the .TLB file from the pre-defined .IDL, and then doing the "Implement Interface" operation against the .TLB.





Re: Visual C++ General VS2005 Implement an existing IDL

Vedran Bratic

What do you mean I already did what you said... but your "steps" are not precise enough...
" 1) Add the .IDL file to the project and build it to create the .TLB file. "
-> you cannot just "add" a .IDL to the project (what kind of project anyway ). If you mean an ATL project, they have their own IDL and a project cannot have 2 of them, as far as I know...

" 2) Use the wizard to add a new "ATL Simple object" class. "

" 3) Select the new class in Class View, right-click, Add, Implement Interface..., select File, and point to the .TLB "

-> what name should this object have If I use one of the interface names of the IDL then I cannot do the step 3. If I use an other name, then the interface of the the TLB file of my project is not the same anymore...


I already spent over a week on understanding the problem and searching a solution. I tried different ways, but nothing worked well. So I would appreciate I you could be a bit more precise...

regards,
vedran









Re: Visual C++ General VS2005 Implement an existing IDL

Sdi

If you copied the interface and class definitions from the existing .IDL into your new project's .IDL, that will do for 1).

The class name you use for 2) doesn't matter; pick whatever you like. You'll end up with an empty "IMyClassName" in the .IDL, which you can ignore. As you deduced, the class name can't match any of the existing classes in the .IDL.

After you do 3), you'll end up with an ATL COM object that implements two interfaces; the empty IMyClassName ATL gave you and the one from the "Implement Interface" step.

Naturally, the new class will have its own CLSID and IID values; if you want, you can change them to match the original .IDL.

WRT "you cannot just "add" a .IDL to the project ....they have their own IDL and a project cannot have 2 of them, as far as I know": yes, you can have as many .IDL files in a project as you want. Each .IDL will generate matching _i.c, _p,c, .h, and .TLB files. However, they also each put information into the common dlldata.c file, which is why that file says

"To completely reconstruct this file, delete it and rerun MIDL

on all the IDL files in this DLL, specifying this file for the

/dlldata command line option" [emphasis added]





Re: Visual C++ General VS2005 Implement an existing IDL

Vedran Bratic

Thank you for the details (and expenation about IDLs)... Now I'm sure that I followed the instructions right.

For each interface in my IDL, I created an ATL-Simple-Object with a prefix E (Step 2). With this I also got interfaces like IEDObject, IEDAccessKey and so on - but like you said I can ignore it. I right clicked on the classes like CEDObject or CEDAccessKey and asked to implement the interfaces IDObject and IDAccessKey. I got the methods of thous interfaces in my EDObject.h and EDAccessKey.h files, where I can implement them (or in the cpp-files). So far so good...

Unfortunately after creating 150 classes and configuring like described above, i cannot compile. I seem to get an error for each inheritance. In the IDL whitch I got, the IDAccessKey inherits from IDObject. I don't know If I should consider this somehow...

The error I get is:
"Fehler 1 error C2504: 'IDObject': Basisklasse undefiniert "
(in the project .h file that was generated by the IDL compiler)

It means like the base class IDObject is undefined.

Is there anything that I forgot What am I missing

Thanks for every advice,
Vedran










Re: Visual C++ General VS2005 Implement an existing IDL

Sdi

If IDAccessKey is based on IDObject, then when you tell CEDAccessKey to implement IDAccessKey, you also have to tell it to implement IDObject. But IDObject shouldn't be a base of IDAccessKey; it should just show up in the COM interface map.

You can make CEDObject a base class of CEDAccessKey to handle the implementation of IDObject, but you'll have to re-implement IUnknown to make sure you don't violate COM identity rules





Re: Visual C++ General VS2005 Implement an existing IDL

Vedran Bratic

First I realized I should use the "Custom" flag and not the "Dual" flag for the Interface while creating an ATL simple objects. Right now I get the following error when I compile the code:

error C2259: cannot instantiate abstract class

----------< snip >---------------
...
DAccessKeyImpl.cpp
c:\programme\microsoft visual studio 8\vc\atlmfc\include\atlcom.h(1799) : error C2259: 'ATL::CComObject<Base>': Instanz von abstrakter Klasse kann nicht erstellt werden
with
[
Base=CDAccessKeyImpl
]
aufgrund folgender Member:
"HRESULT IDObject::get_ObjectType(DObjectType *)": ist abstrakt
d:\workspace\simple_03\simple_03\simple_03.h(282): Siehe Deklaration von 'IDObject::get_ObjectType'
c:\programme\microsoft visual studio 8\vc\atlmfc\include\atlcom.h(1788): Bei der Kompilierung der Klassen-template der HRESULT ATL::CComCreator<T::CreateInstance(void *,const IID &,LPVOID *)-Memberfunktion
with
[
T1=ATL::CComObject<CDAccessKeyImpl>
]
c:\programme\microsoft visual studio 8\vc\atlmfc\include\atlcom.h(1879): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "ATL::CComCreator<T".
with
[
T1=ATL::CComObject<CDAccessKeyImpl>
]
c:\programme\microsoft visual studio 8\vc\atlmfc\include\atlcom.h(1875): Bei der Kompilierung der Klassen-template der HRESULT ATL::CComCreator2<T1,T2>::CreateInstance(void *,const IID &,LPVOID *)-Memberfunktion
with
[
T1=ATL::CComCreator<ATL::CComObject<CDAccessKeyImpl>>,
T2=ATL::CComCreator<ATL::CComAggObject<CDAccessKeyImpl>>
]
d:\workspace\simple_03\simple_03\daccesskeyimpl.h(91): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "ATL::CComCreator2<T1,T2>".
with
[
T1=ATL::CComCreator<ATL::CComObject<CDAccessKeyImpl>>,
T2=ATL::CComCreator<ATL::CComAggObject<CDAccessKeyImpl>>
]
--------------< snip-end > -----------------

In my project there is the Interface IDObject and IDAccessKey. The ATL simple object DObjectImpl is implementing the IDObject interface and the object DAccessKeyImpl is implementing the IDAccessKey interface.

IDAccessKey is derived from IDObject, and that seems to produce the problem...

The Implementation of the method is in the DObjectImpl-Class but DAccessKeyImpl doesn't see it. What is the connection between DAccesskeyImpl and DObjectImpl that I'm missing

I was looking for an ATL example project with inheritance but I couldn't find anything useful...

thanks for help,
vedran










Re: Visual C++ General VS2005 Implement an existing IDL

Sdi

COM doesn't inherit implementations, just interfaces. You need to implement IDObject on your IDAccessKey object; just have the functions call the implementation in the parent class subobject.



Re: Visual C++ General VS2005 Implement an existing IDL

Vedran Bratic

Thanks for your help Sdi...
I also found a way to inherit implementations in the google-newsgroups, but you cannot do it with wizzards only manualy...

It's quite funny that nobody developed a program for creating a valid C++-Application out of an IDL-file withing one klick. (It looked so self-evident to me...:-) )

anyway, tx
Vedran