Introduction to ATL (1)

Source: Internet
Author: User
Tags win32 window

Introduction to ATL (1)

As ATL/COM/ActiveXI would like to improve the popularity of our forum and write some articles to attract more com users.Newbie. Every day, you will see some problems that new users encounter when passing parameters, such as custom structure types, arrays, interfaces, and other parameter types. This article mainly makes some fear of COMNewbie knows what basic knowledge to master and how to use comComponents are the simplest to enable themI have a rough idea.

What is ATL?

ATL (Active Template Library) is a template library dedicated for Developing COM components. The latest version is atl7.1 (.. net), which modifies some bugs in the earlier version of atl3.0 (released with Visual C ++ 6.0.

What background knowledge is required for learning ATL?

1. com basics. Because ATL is for com, a solid knowledge of COM can help you. It is best to take a look at "com essence theory".

2. c ++ template knowledge.

3. Basic Windows knowledge, especially windows in Win32. Because ATL encapsulates the user interface (UI), it is much more complicated to create a form and process a message than MFC.

4. STL knowledge. ATL and STL have similarities in data set management. If you have STL as the foundation, it is easy to understand the set and enumeration in ATL.

What about ATL?

Some basic C ++ programmers have used STL, which saves us a lot of time and encapsulates vector, list, queue, and other generic algorithms. In the past, some of us may have some doubts about it, but now he has been recognized by us. ATL corresponds to com. Although there were a lot of bugs when it first came out, there were very few bugs in atl7.1! We can use it with confidence. Some people must have read Don box's "com Essence Theory". After reading it, they will certainly say that it is so troublesome to write a COM component! The most important thing is to pay attention to the reference count, and there are so many unclear guids. Even those who just learned com don't know how to create a new guid or what they are all useful. Not to mention the creation of a class factory. This stuff may scare away a batch of companies who want to learn com, and there is very little information about com, A few good books are about theoretical knowledge. I want to give a few examples. It's just a tiger's day! If you use ATL to create a component or control, you can use the wizard in less than one minute. Haha! There is an in-depth analysis of ATL book worth reading. Some people will say that MFC can also quickly create a control, right. If you want to go deep into the bottom layer, or Use ATL, it will give you more understanding of the essence of COM. I am using atl7.1 as a component. It can be used in VB6 or vc7 without any. Net Library support.

ATLWhere are the disadvantages?

The disadvantage of ATL is its support for forms. It only encapsulates the most basic write functions, and almost all controls must be completed through the Win32 window API. I have suffered a long time. It may be a waste of time to create a combox. However, this will also allow you to experience the pleasure of directly using APIs (great flexibility ). If you want to create a component or development kit, do not bring the interface unless you have. There are many advantages over forms. One is high flexibility. You can write Interfaces Based on your own style (users hate Development kits or controls that hate dialogs and weird buttons ). Another advantage is that if your development kit contains pure interfaces (without interface interfaces), you can easily transfer custom structures between interfaces. I have read a lot of controls (or COM components) written by others, call more than a dozen parameters of an interface method, and it takes a long time for customers to learn about its documentation (because their parameters are inexplicable, eg: Create (BSTR Str )). The purpose of the control or com development kit is to be used by the customer. However, we also need to ensure that the control is simple and flexible, so that the customer can use it as far as possible. I think many people are willing to use custom structures! Because it can be directly defined on the client. However, you should note that when passing the structure, the pointer must be passed for both the [in] and [out] attributes. The reason is very simple: the interface can be said to be struct (of course, they are different from each other ). The interface is virtual, but the struct is not.

Write it here first. The next article will introduce some practical things. Let's discuss the difference. My MSN: wangweixing2003 @ hotmail.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.