COM+ Interfaces and The Interface Definition Language
Gopalan Suresh Raj

Food for Thought...

import "unknwn.idl";

[uuid(6B6EBD41-01C0-11d3-97EE-006097A7D34F), dual]
interface IDictionary : IDispatch {
  HRESULT lookupWord ([in] BSTR word, [out, retval] BOOL* found);
  HRESULT addToDictionary ([in] BSTR word);
};
 
[uuid(6B6EBD42-01C0-11d3-97EE-006097A7D34F), dual  ]
interface IThesaurus : IDispatch {
  HRESULT getSynonym ([in] BSTR word, [out, retval] BSTR* meaning);
};
 
[uuid (6B6EBD40-01C0-11d3-97EE-006097A7D34F), version (1.0)]
library EditingToolsLib {
 importlib ("stdole32.tlb");
 
 [uuid(6B6EBD43-01C0-11d3-97EE-006097A7D34F)]
 coclass EditingTools {
  interface IDictionary;
  interface IThesaurus;
 };
}

                                                                                                               
- Yours Truly

Dim spellChecker As IDictionary                                      'declare interface-based reference
Set spellChecker = New EditingTools                            
'use CoCreateInstance to load component
bool found = spellChecker.lookupWord ("cornucopia")
'invoke IDictionary.lookupWord method
Dim thesaurus As IThesaurus                                           
'declare interface-based reference
Set thesaurus = spellChecker                                         
'use Query Interface to coerce type
If found = True Then
 Dim meaning = thesaurus.getSynonym ("cornucopia")
 'invoke IThesausus.getSynonym method
Else
 spellChecker.addToDictionary ("cornucopia"          
'invoke IDictionary.addToDictionary method
End If
Set spellChecker = Nothing                                             
 'release reference to object
Set thesaurus = Nothing                                                 
 'release reference to object
                                                                                                               
- Yours Truly


COM+ Interfaces are the medium with which clients communicate with a COM+ component. An interface is a collection of one or more operations that provide one type of functionality. Every COM+ component exports one or more interfaces. Clients use interface pointers to connect to a COM+ component.

Interfaces have symbolic names that allow you and me to converse about them in an understandable way. However, the real name of an interface is its unique Interface ID (IID). To allow programmers to use the IID of an interface, the IID is given a symbolic name, which generally is the interface name prefixed with IID_ (for e.g., IMyComponent's GUID symbolically referred to as IID_IMyComponent).

As we discussed earlier, an interface ID is a type of GUID. It is this binary GUID that allows an interface to be named uniquely and unambigously. An interface establishes a protocol of communication between the client and the COM+ component implementation. The method parameters define the syntax of this protocol. The documentation defines the semantics of this protocol. Therefore, once defined and published, an interface should not change. This is to ensure backward compatibility with existing clients which may still be using older versions of the same component.

COM+ interfaces are defined in IDL using the
interface keyword. In C++, they are exposed as pure abstract base classes so that they define a physical layout in memory. COM+ interfaces have three major aspects:
1. COM+ interfaces are a collection of logical operations
2. COM+ interfaces have a physical virtual table representation in memory
3. COM+ interfaces define a packet level format for representing the method call invocations across execution contexts.

Interfaces and the Interface Definition Language
To achieve language independance, and location transparency, all COM+ interfaces have to first be defined in an Interface Definition Language (IDL). The IDL uses an attribute extended C syntax. These attributes act as footnotes to disambiguate C-isms. Each interface has to have an explicit and unique Interface ID defined in its IDL. Similarly, method parameters have to have an explicit direction. An
[in] value denotes that the value is sent from the client to the component. An [out] value denotes that the value is sent from the component to the client.

import "unknwn.idl";

[uuid(31325851-E808-11d3-987E-006097A7D34F), object]
interface IEmployee : IUnknown {
  HRESULT getName ([out, retval] BSTR* name);
  HRESULT getSSN ([out, retval] BSTR* ssn);
};
 
[uuid(31325852-E808-11d3-987E-006097A7D34F), object]
interface IDeveloper : IEmployee {
  HRESULT developCode([in] BSTR specs,
                                 [in] BSTR design,
                                 [out, retval] BSTR* code)
;
};
 
[uuid(31325853-E808-11d3-987E-006097A7D34F), object]
interface IArchitect : IDeveloper {
  HRESULT writeSpecifications ([out, retval] BSTR* specs);
  HRESULT produceDesignDocs ([in] BSTR specs,
                                            [out, retval] BSTR* docs)
;
};
 
[uuid (31325850-E808-11d3-987E-006097A7D34F), version (1.0)]
library Roles {
 importlib ("stdole32.tlb");

 [uuid(31325854-E808-11d3-987E-006097A7D34F)]
 coclass DevelopmentTeam {
  interface IArchitect;
  interface IDeveloper;
 };
}

This example defines multiple COM interfaces like IEmployee, IDeveloper, and IArchitect. Also note that the definition of IUnknown is imported from another file called iunknwn.idl. When this file is compiled using the IDL compiler midl.exe it generates a type library for this IDL. We will talk about type libraries shortly. We will discuss IDL in a separate section shortly.

 

click here to go to
My Basic COM+ Tutorial...
click here to go to
My Advanced COM+/DNA Tutorial HomePage...

 

About the Author...
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He is contributing author to a couple of books "Enterprise Java Computing-Applications and Architecture" and "The Awesome Power of JavaBeans". His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia© site (http://www.execpc.com/~gopalan) or mail him at gopalan@execpc.com.

 


Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since March 13,1999.

Last Updated : Mar 14,'99

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-2000, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.