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
- Right-click the project name you wish to add the ATL simple object to in Solution Explorer or Class View.
- Select Add from the shortcut menu, then select Add Class.
- 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.
- On the Options page of the ATL Simple Object wizard, specify additional project options.
- 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 DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc. To practice and improve yourself in the interview, you can also check out Top 100 SQL problems, Interview experience, Coding interview questions, and the Ultimate guide path for interviews. Do upvote our blog to help other ninjas grow. Happy Coding!!
