Build lightweight ATL COM objects with the first part, the author: Zhao Xiangning
This article assumes that you are familiar with C and COM. Summary: The ATL - the Active Template library, its design is designed to make people develop COM objects with C conveniently. ATL itself is quite small and flexible, this is its biggest advantage. Use it to create a lightweight, self-contained, can be reused, without any additional runtime DLLS support. Due to a good reputation in COM technology, more and more programmers have entered or enter COM's programming world. It is like the ice beer in the summer, never disappoints you. Unfortunately, as a C programmer, C never share the ultimate of COM, and I have a unique momentum of coming to COM. If it is, if it is left, peaceful coexistence between C and COM, IUNKNOWN is implemented in each object again. I will definite the future C compiler and linker to realize the natural unconscious correspondence and mapping between C objects and COM objects. The current environment is only in the lab, so it is definitely not a product you can purchase today. It is the event template library --ATL. Why use the ATL? ATL is gradually expanded in a single-tier application, and distributed applications have gradually become born in such an environment such as mainstream. Its original version is in four C header files, one is still empty . The excellent architecture it formed is specifically used to develop a lightweight COM component required for modern distributed applications. As a modular standard component, ATL is unlike the MFC has a thick infrastructure, saving the library that makes hundreds of programmers to easily implement iUnknown and iClassFactory once again. The ATL architecture is not intended to include all, nothing. The first version provides very in place for implementing IUNKNOWN, ICLASSFACTORY, IDISPATCH, ICONNECTIONPOINTCONTAINER and COM envoys. In addition to writing ActiveX controls, the second version is also enhanced in the initial version of the ATL class. ATL does not provide a collection of collections and strings, which assumes these processes you use standard C libraries; do not support ODBC - this world is moving to COM-based unwanted packaging; Supporting Winsock packages - Sockets itself is also new; ATL does not support full Win32 API package class -ATL2.0 implementation mechanism provides dialogs and WNDPROCS support. In addition, there is no document / view model in the MFC in the ATL. Instead, ATL is more flexible and flexible through COM interfaces (such as ActiveX controls) and communication modes between UI-based objects. It is very important to use the right tool. If you are writing an invisible COM component, ATL is more likely to match the MFC, from the development efficiency, scalability, runtime performance, and executable size, ATL may be the best choice. The code generated by the ATL is more faster than the MFC based on the user interface of the modern ActiveX control. On the other hand, ATL needs more COM knowledge than the MFC's class wizard. ATL is the same as STL, which has no help to single-layer applications, while MFC maintains its advantage in this regard. The ATL design is largely inspired by STL, and STL has been included in a part of a standard C library with all ANSI / ISO compatible C compilers.
Like STL, ATL boldly uses C templates. The template is one of the more controversial features in C . Each use of improper use can cause confusion, reduce performance, and difficult to understand. The versatility effect and type safety characteristics generated by the template are not to be in other ways. ATL is in two extremes like STL. Fortunately, while l Gold Gold C templates, compilers and linker technology are also developing forward in the same pace. STL and ATL reasonable selection for current and future development. Although the template is widely used inside, you don't have to use an ATL technology, you don't have to use it or care about the sharp arc in those templates. Because the ATL itself comes with an ATL Object Wizard (see Figure 1): Figure An ATL Object Wizard The Object Wizard generates a large amount of ATL template-based object implementation code (ie, frame code). These default object types are listed in Schedule. The ATL Object Wizard allows anyone to quickly build COM objects and let it run within minutes, don't take into account the details of COM or ATL. Of course, in order to fully control the ATL, you must master C , templates, and COM programming technology. For large object classes, the custom interface is output as long as the method implementation is added to the default implementation generated by the ATL object (frame code), which is also the focus of most developers to implement the COM object. When you first contact ATL, its architecture gives people feel mysterious and incredible. Helloatl is the simplest ATL-based process server source code and the same process in the same process implemented in SDK (purely C ). Before you really build a COM component, the code needs to be repeated and modified multiple times. For mainstream component developers who want to accelerate the development of COM components, the ATL architecture is not a big problem, because the object wizard produces all the frame code required, just want to join the method definition. For serious COM developers and system programmers, ATL provides an advanced, scalable architecture that establishes COM components with C . Once you understand and master this architecture and drive the object wizard, you will see ATL's performance and powerful features, it can be comparable to the original COM programming technology. Another reason for using ATL development COM components is the Visual C 5.0 Integrated Development Environment (IDE) to ATL's height support. Microsoft integrates the interface definition language (IDL) of ATL to the C editor in Visual C 5.0 . (to be continued)