Table of contents
1.
Introduction
2.
Multiple Dual Interfaces
3.
Exposing a Single IDispatch Interface
4.
Combining Multiple Dual Interfaces in a Single Implementation of IDispatch
5.
Nonextensible Attribute
6.
Frequently Asked Questions
6.1.
What is an Object Model?
6.2.
Is it good to combine Multiple Dual Interfaces in a Single Implementation of IDispatch?
6.3.
What is a Virtual Table?
7.
Conclusion
Last Updated: Aug 13, 2025
Medium

ATL Multiple Dual Interfaces

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

Introduction

Hey Ninjas!! Welcome to another article on Advanced Template Library. Today we will learn about Multiple Dual Interfaces in Advanced Template Library (ATL). The Advanced Template Library comprises all template-based C++ classes. It is helpful in creating small Component Object Model objects. The Component Object Model is a platform-independent object-oriented system used for developing binary software components.

ATL Multiple Dual Interfaces

Dual Interface allow users to access the methods of the class in two different ways. The first way is using dispinterface methods. The second way is using VTABLE (virtual table). The dispinterface is used when the application exposes its existing non-VTABLE functions through Automation.

Without further ado, let's get started. 

Multiple Dual Interfaces

ATL comes with a feature of Multiple Dual Interfaces. The Multiple Dual Interfaces allow users to have the flexibility of VTABLE and dynamic binding. This makes the availability of classes to the scripting language and C++. The scripting language is a programming language where scripts are written for a runtime environment. The use of multiple dual interfaces ensures that there is less code complexity and no loss of functions.

Exposing a Single IDispatch Interface

ATL provides the method to expose multiple dual interferences on a single object. This can be achieved by deriving the multiple specializations of IDispatchImpl. This class contains the static members of type CComTypeInfoHolder. This static member manages the information type of dual interface. ATL also allows multiple queries for the IDispatch interface. In such cases, you also need to use the COM_INTERFACE_ENTRY2 macro. It specifies the base class of the IDispatch. 

Example:

COM_INTERFACE_ENTRY2(IDispatch, IMyDualInterface)
You can also try this code with Online C++ Compiler
Run Code

 

Here only one IDispatch interface is exposed. In such cases, you can only access the objects of your class.

Combining Multiple Dual Interfaces in a Single Implementation of IDispatch

ATL doesn't have the feature to combine Multiple Dual Interfaces in a Single Implementation of IDispatch. You can manually implement such features. The following are the different ways to combine multiple dual interfaces into a single implementation:

Combining Multiple Dual Interfaces in a Single Implementation of IDispatch Image
  • Creating a templated class that contains all the separate IDispatch interfaces.
     
  • Creating a new object to carry out the QueryInterface function. QueryInterface() is used to obtain an interface pointer of an another class from the exiting interface pointer.
     
  • Using the nested objects with typeinfo. The typeinfo is a header file which defines several types associated with the type identification operator, which yields information about both static and dynamic types.
     

The above approaches are not practically feasible. This might result in code complexity and namespace collisions.

Nonextensible Attribute

The nonextensible attribute gives information to client languages (like Visual Basic) that can be used to enable full code verification during compile time. This attribute is helpful when the dual interface is not enabled during runtime. This attribute prevents bugs in the client code during runtime.

Syntax:

[nonextensible]
You can also try this code with Online C++ Compiler
Run Code


Let's understand with an example.

Code:

#include "header.h"
[module(name="ATLFIRELib")];
[export] typedef long CODESTUDIO;


[dual, nonextensible, ms_union, oleautomation,
uuid("96842514-9E4C-2804-AB98-030098666741")]
__interface CodingNinjas
{
   CODESTUDIO procedure (int x);
};
You can also try this code with Online C++ Compiler
Run Code


Explanation:

 In the above code snippet, we had created an interface with the name CodingNinjas. It is a dual and nonextensible attribute. It is helpful when the dual interface is not enabled during the runtime of the code.

Frequently Asked Questions

What is an Object Model?

The Object Model visualizes the software elements as objects. 

Is it good to combine Multiple Dual Interfaces in a Single Implementation of IDispatch?

No, combining Multiple Dual Interfaces into a Single Implementation of IDispatch would increase the complexity of the code.

What is a Virtual Table?

A virtual table is a lookup table of functions used to solve function calls in dynamic binding.

Conclusion

In this article, we have discussed the details of Multiple Dual Interfaces and nonextensible Attributes in ATL.

We hope that the blog has helped you enhance your knowledge regarding ATL Multiple Dual Interfaces. 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 blogs to help other ninjas grow. Happy Coding!!

Live masterclass