Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Writing COM Clients with Late and Early Binding


October 1998/Writing COM Clients with Late and Early Binding/Sidebar

Dual Interfaces


One heavily used but often misunderstood term in COM is dual interface. Put simply, dual interfaces are interfaces that support both early and late binding. Much of the literature on COM implies that Microsoft wants your interfaces to be dual, so you can have the best of both worlds. The problem is, as in life, there are always compromises.

Late binding comes from Visual Basic, so it carries all the type limitations of that language. Basically, if you can't do it in VB, you can't do it in late binding, because you are limited to the Visual Basic types. Thus, late-bound method calls on an interface cannot handle things such as structures, pointers, linked lists, etc., and passing arbitrary length arrays is very clumsy. Fortunately, you can always create an interface that supports early binding only. This will enable the caller to pass almost any standard C structure, data structure, pointer, etc. that RPC supports. However, if you use dual interfaces, your early-binding interface will be constrained to the data types allowed by its less intelligent, late-binding, Siamese twin.

The rules are as follows:

If you are writing a server for use with any language, VB included, and you want to support late and early binding, you should definitely use dual interfaces. All interfaces will derive from IDispatch. You will have to forgo the ability to pass more esoteric, pointer-heavy C data types, but this is often not a sacrifice.

If you writing a COM server designed to be used exclusively by C++ clients, you may use what are called custom interfaces. These interfaces derive from IUnknown, not IDispatch. This means that the COM class will support only early binding. VB may still be able to use this object via early binding, but only if no, structures (except for VARIANTs), linked lists, etc. are used. If they are used, VB will complain that the object uses unsupported data types.

If you have a legacy COM component, or an old automation server, it may support only late binding. If you look at the IDL, you may notice that the interfaces are declared as dispinterfaces. This means late binding exclusively. Early binding is a more recent development.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.