Table of contents
1.
Introduction
2.
Implementing a Dual Interface
2.1.
ATL Simple Object Wizard
2.2.
Implement Interface Wizard
3.
Implementing IDispatch
4.
Multiple Dual Interfaces
5.
Dual Interfaces and Events
6.
Frequently Asked Questions
6.1.
What is a dual interface?
6.2.
Can you have two dual interfaces in one class?
6.3.
What’s the difference between COM and DCOM?
7.
Conclusion
Last Updated: Aug 13, 2025

How to Implement a dual interface?

Author Nilesh Kumar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The methods of a dual interface can be accessed as either dispinterface methods or vtable methods. From an ATL standpoint, this section discusses a few dual interface capabilities.

Creating compact, quick Component Object Model (COM) objects is made possible by the Active Template Library (ATL), a collection of template-based C++ classes. The main COM features, such as connection points, tear-off interfaces, dual interfaces, standard COM enumerator interfaces, stock implementations, and ActiveX controls, have particular support in this version.

how to implement dual interface

Implementing a Dual Interface

The IDispatchImpl class, which offers a default implementation of the IDispatch methods of a dual interface, can be used to implement a dual interface.

To use this class:

  • Create a type library and define your dual interface.
  • Draw inspiration for your class from an IDispatchImpl specialization (pass information about the interface and type library as the template arguments).
  • To expose the dual interface through QueryInterface, add an entry (or entries) to the COM map.
  • In your class, implement the vtable portion of the interface.
  • Make sure your objects can access the type library holding the interface definition at runtime.

ATL Simple Object Wizard

The ATL Add Class dialogue box and the ATL Simple Object Wizard can be used to build a new interface and the class that will implement it.

Implement Interface Wizard

If you already have an interface, you can use the Implement Interface Wizard to extend an existing class with the required base class, COM map entries, and skeleton method implementations.

 

Note: You might need to modify the produced base class so that the IDispatchImpl base class receives the major and minor version numbers of the type library as template arguments. The type library version number is not checked for you by the Implement Interface Wizard.

Implementing IDispatch

As long as you have a type library describing a corresponding dual interface, you can use an IDispatchImpl base class to provide an implementation of a dispinterface by simply specifying the necessary entry in the COM map (using the COM_INTERFACE_ENTRY2 or COM_INTERFACE_ENTRY_IID macro). For instance, this is a popular way to build the IDispatch interface. Both the ATL Simple Object Wizard and the Implement Interface Wizard add the proper entry to the map as they both presume that you want to implement IDispatch in this manner.

To assist you in implementing dispinterfaces without needing a type library providing the specification of a compatible dual interface, ATL provides the IDispEventImpl and IDispEventSimpleImpl classes.

Multiple Dual Interfaces

You could combine the benefits of multiple inheritances with the advantages of a dual interface (that is, the adaptability of both vtable and late binding, making the class available to scripting languages as well as C++).

It is not advisable to expose many dual interfaces on a single COM object, despite the fact that it is feasible to do so. There can only be one IDispatch interface exposed if there are numerous dual interfaces. The methods are available to make sure of this come with drawbacks like function loss or more sophisticated code. The developer who is adopting this strategy should carefully balance the benefits and drawbacks.

Dual Interfaces and Events

Even though it is technically possible to build an event interface as a dual, there are some compelling design arguments against doing so. The main cause is because the event's source will only fire it via the vtable or via Invoke, not both. It is obvious that the interface should have been a pure vtable interface if the event source fires the event as a direct call to a vtable function because the IDispatch methods will never be called. The vtable methods will never be used if the event source fires the event as a call to Invoke, making it obvious that the interface should have been a dispinterface.

It will be necessary for clients to implement a portion of an interface that will never be used if you specify your event interfaces as duals.

Note: Generally, this reasoning does not hold for dual interfaces. Duals are a rapid, practical, and well-supported method of implementing interfaces that are usable by various clients from the standpoint of implementation.

Frequently Asked Questions

What is a dual interface?

IDispatch interface and vtbl-based interface are both supported by dual interfaces. The strength and speed of a vtbl-based interface can therefore be used in non-scripting environments while also being used in scripting environments like VBScript. The discussion could then quickly turn into an analysis of dual interface problems, so be ready for this turn.

Can you have two dual interfaces in one class?

Yes. One class may include two dual interfaces, but only one of them may be the default. Due to the nature of dual interfaces, you cannot work with two dual interfaces simultaneously.

What’s the difference between COM and DCOM?

Once more, there is no right or wrong answer to this issue. Since DCOM extends COM, every DCOM object is also a COM object, and all COM objects are eligible to take part in DCOM transactions. MULTI QI (multiple QueryInterface()), security contexts, and other distributed environment improvements/optimizations were introduced by DCOM. DCOM made clear the significance of surrogate processes by showing that in-proc servers could not be run on distant machines. To do it, you require a surrogate procedure.) Introducing load balancing was DCOM.

Conclusion

In this article, we have extensively discussed the details of implementing the dual interface along with ATL Simple Object Wizard, ATL Simple Object Wizard, Implementing IDispatch, Multiple Dual Interfaces, and Dual Interfaces and Events.

We hope this blog has helped you enhance your knowledge about the implementation of dual interface, and You can refer to our guided paths on the Coding Ninjas Studio platform to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problemsInterview experienceCoding interview questions, and the Ultimate guide path for interviews. Do upvote our blog to help other ninjas grow. Happy Coding!!

thankyou.png

 

 

Live masterclass