|< BACK  NEXT >|
Often times, a COM developer has to deal with multiple IDL files.
Consider the scenario where several VCR manufacturers got together and defined an interface for video signals, IVideo.
Now all the VCR manufacturers can get back to work and create their own IDL file defining the interface. However, this is not practical; some manufacturers can make a mistake in defining the interface. Moreover, if the interface had to be extended, every manufacturer will have to edit their respective IDL file.
In fact, COM defines many data types and core system interfaces, including IUnknown, that would cause a maintenance nightmare if not defined at one place.
Ideally (or is it IDLly?), the interface should be defined in one file. Any other IDL file should be able to reference the interface from this file.
Now that the case for multiple IDL files is made, you already know from a previous section that you need to use the import keyword to access the definitions from a different IDL file.
Many COM-defined core interfaces are in SDK files oaidl.idl and ocidl.idl. It is very common to see these two files imported at the beginning of an IDL file. Tools such as ATL wizard will import these two files in the IDL file (rather blindly, but that s okay).
import "oaidl.idl"; import "ocidl.idl";
In order to prevent duplication of definitions in a type library, you will need to judiciously use the importlib keyword. If you use ATL wizard, it will importlib SDK-defined type libraries, stdole2.tlb and stdole32.tlb, in the library section.
Blindly importlib ing these two type libraries is perfectly okay. In fact, you should always do so. Depending on your needs, you may wish to importlib additional type libraries.
|< BACK  NEXT >|