Table of contents
1.
Introduction 
2.
Introduction to COM
3.
How to Implement ATL Object? 
3.1.
Steps to Implement an ATL simple object to your ATL COM project
4.
Supporting IDispatch and IErrorInfo, IDispEventImpl in ATL
4.1.
Supporting IDispatch and IErrorInfo
4.2.
Supporting IDispEventImpl
5.
Changing the default class factory and aggregation model in ATL
5.1.
DECLARE_CLASSFACTORY
5.2.
DECLARE_AGGREGATABLE 
6.
How to Implement a dual interface?
7.
Frequently Asked Questions
7.1.
What Is the ATL Control-Hosting API?
7.2.
What is the class description of CWindow?
7.3.
What is the process?
8.
Conclusion
Last Updated: Aug 13, 2025

Supporting IDispatch and IErrorInfo, IDispEventImpl in ATL

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

Introduction 

The common TLA (three-letter acronym) used everywhere in the Windows industry is COM (Component Object Model). Numerous new technologies based on COM are constantly being released. The documentation uses a lot of terminologies, such as COM object, interface, server, and so forth, but it all presumes you are familiar with COM's functionality and use.

image.png

Introduction to COM

Simply described, COM is a technique for exchanging binary code between various languages and applications. Contrary to the C++ methodology, which encourages source code reuse, ATL is the ideal illustration of this. Reusing code at the source level is effective, but only in C++. Along with the potential for name clashes, it increases project bloat caused by having several copies of the same code.

Using DLLs, Windows enables binary code sharing. Since Windows apps reuse kernel32.dll, user32.dll, etc., this is how they work. However, because the DLLs are designed with a C interface, only C or languages that comprehend the C calling convention can utilize them. This shifts the responsibility for sharing from the DLL to the programming language implementer.

By defining a binary standard, which requires that the binary modules (the DLLs and EXEs) be compiled to fit a specified structure, COM provides a solution to each issue. The standard also details the precise memory layout used for COM objects. Additionally, the binaries must not rely on language-specific characteristics, such as C++'s name decoration. After that, the modules can be accessed from any programming language. A binary standard makes it much simpler for people who develop later and need to utilize those binaries since it places the responsibility of compatibility on the compiler that creates the binaries.

The structure of COM objects in memory uses the same structure.

How to Implement ATL Object? 

Your project must have been completed as an ATL application or an MFC program with ATL support if you want to add an ATL (Active Template Library) object. You can incorporate ATL support for an MFC program by adding an ATL object or using the ATL Project Wizard to create an ATL application.

You can specify COM interfaces when you first build your new ATL object. Later on, you can add them by using the Implement Interface command from the Class View shortcut menu.

Steps to Implement an ATL simple object to your ATL COM project

  1. Right-click the project name you wish to add the ATL simple object to in Solution Explorer or Class View.
  2. Select Add from the shortcut menu, then select Add Class.
  3. Click ATL Simple Object in the Templates pane of the Add Class dialogue box, and then click Open to bring up the ATL Simple Object Wizard.
  4. On the Options page of the ATL Simple Object wizard, specify additional project options.
  5. To add the object to your project, click Finish.

Supporting IDispatch and IErrorInfo, IDispEventImpl in ATL

Supporting IDispatch and IErrorInfo

To provide a default implementation of the IDispatch Interface portion of any dual interfaces on your object, you can use the template class IDispatchImpl.

Your object must support the ISupportErrorInfo Interface interface if it uses the IErrorInfo interface to communicate errors to the client. If your object only has one interface that creates errors, the template class ISupportErrorInfoImpl offers a simple implementation method.

Supporting IDispEventImpl

Your ATL class can enable connection point sinks using the template class IDispEventImpl. Using a connection point sink, your class can respond to events sent by COM objects that are external to it. The event sink map from your class is used to map this connection point sinks.

To properly construct a connection point sink for your class, you must carry out the following actions:

  • Each external object's type libraries should be imported.
  • Declare the interfaces for IDispEventImpl.
  • Declare an event sink map
  • Unadvice and Advise the connection points.

All the procedures required to implement a connection point sink can be completed by changing the class's header file (.h).

Changing the default class factory and aggregation model in ATL

The default class factory and aggregation model for your object are defined by ATL using CComCoClass. CComCoClass specifies the two macros listed below:

DECLARE_CLASSFACTORY

DECLARE_CLASSFACTORY determines that the class factory is CComClassFactory.

DECLARE_AGGREGATABLE 

DECLARE_AGGREGATABLE is a statement stating that your object can be aggregated
 

Two more macros define a class factory:

  • DECLARE_CLASSFACTORY_AUTO_THREAD 
  • DECLARE_CLASSFACTORY_SINGLETON

ATL also uses the typedef approach to implementing a default behavior. In the  DECLARE_AGGREGATABLE macro, for instance, a type called _CreatorClass is defined using typedef and then used as a reference throughout ATL. It should be noted that if a typedef in a derived class has the same name as the typedef in the base class, ATL will use your declaration and override the default behavior.

How to Implement 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.IDispatch can be implemented by ActiveX or OLE objects for use by ActiveX clients like Visual Basic. Through the use of IDispatch::GetIDsOfNames and IDispatch::Invoke, the object's attributes and methods can be accessed.

To implement 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.

Frequently Asked Questions

What Is the ATL Control-Hosting API?

Any window can serve as an ActiveX control container thanks to the control-hosting API from ATL.

These routines are accessible by ATL80.dll and are available as source code, so they can be statically or dynamically linked to your project. The table below contains a list of the control-hosting operations.

What is the class description of CWindow?

Offers the GetDlgControl function, which, given the ID of its host window, returns an interface pointer on a control. Additionally, window management is often made simpler by the Windows API wrappers supplied by CWindow.

What is the process?

Thread is a unit of execution in Windows.

The setting in which a thread runs is a process.

The threads, not the process, are scheduled by the scheduler.

Thread is regarded as a lightweight process in Unix versions.

The process, not the threads, is scheduled by the scheduler.

 

Conclusion

In this article, we have extensively discussed the details of Supporting IDispatch and IErrorInfo, IDispEventImpl in ATL along with the Introduction to COM, implementation of ATL object, Changing the default class factory and aggregation model, and implantation of the dual interface.    

We hope this blog has helped you enhance your knowledge of The Elliptic Curve DSA. 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.jpg

 

Live masterclass