COM+ Programming A Practical Guide Using Visual C++ and ATL [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

COM+ Programming A Practical Guide Using Visual C++ and ATL [Electronic resources] - نسخه متنی

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید




Interface Definition Language (IDL)


Based on the understanding from the previous section, we can refine our requirements for the new language as follows:



to make C/C++ developers feel right at home



to provide extra information to resolve any C language ambiguities



to provide extra information that is needed to handle remote transparency



Note that the only reason we wish to use a new language is to define an interface. For this, we do not really need a programming languagewe need a declarative language. To achieve this, COM looked to Open Software Foundation Distributed Computing Environment Remote Procedure Call (OSF DCE RPC) IDL. COM IDL simply added a few COM-specific extensions to DCE IDL to support COM-compatible data types and the object-oriented nature of COM such as inheritance, polymorphism, etc.

IDL inherited its syntax from the C/C++ languages. An IDL file primarily contains interface definitions using C++ syntax. In fact, the language supports basic C/C++ data types, structures, enumerators, and even typedefs, thus making it familiar to the large number of C, C++, and Java developers.

IDL Attributes


The extra information that could not directly be derived from C++-style definition, was provided by annotating it to the interface definition. These annotations are referred to as attributes. Attributes are applied to interfaces, each method in the interface, each method parameter, structure definitions, enumeration definitions, and many other definitions. Attributes precede a definition and are placed within brackets. More than one attribute is separated by commas. Again, this style of attribute specification was picked up from DCE IDL. The following example shows our C++ class definition of IVideo (from Chapter 1) transformed into IDL interface definition. For comparison, I have shown the original C++ class definition as well.


// C++ style definition
// IVideo interface
class IVideo : public IGeneral
{
public:
// Obtain the signal value
virtual VRESULT _stdcall GetSignalValue(long* pRetVal) = 0;
};
// Corresponding IDL style definition
[
object,
uuid(318B4AD0-06A7-11d3-9B58-0080C8E11F14),
helpstring("IVideo Interface"),
pointer_default(unique)
]
interface IVideo : IUnknown
{
[helpstring("Obtain the signal value")]
HRESULT GetSignalValue([out, retval] long* plRetVal);
};

Under IDL, an interface is defined using the keyword interface. An interface defined this way uses our familiar vtbl -based mechanism for invoking methods.

Just as a C++ class name is typically prefixed with a C
, the convention that the COM programming community has adopted is to prefix the interface name with an I.

In the above example, note that:



the interface definition IVideo has been annotated with attributes such as object, uuid, etc.



the method definition GetSignalValue has been annotated with helpstring attribute



the method parameter plRetVal has been annotated with attributes out and retval



How do these attributes help us solve our problems? Lets examine various issues that the COM task force considered when defining the language, and see how these attributes can come in handy for facilitating some of these goals.


/ 125