Introduction to ATL ActiveX Development

Source: Internet
Author: User
ATL, Active Template Library Activity Template Library, is a type of Microsoft Program Library, supports the use of C ++ language to write ASP Code And other ActiveX programs. Through the Active Template Library, you can create COM components and then call COM objects through scripts on the ASP page. Such COM components can contain properties pages, dialog boxes, and other controls.

ATL is undoubtedly the most difficult and relatively marginalized Technology in several mainstream technologies. With the development of Internet technology, Microsoft has promoted ActiveX technology as an important part of its network strategy. However, ActiveX control developed by MFC is used, large Code redundancy (so-called "Fat Code"), and must rely on the Runtime Library of MFC to run correctly. Although only some functions of the Runtime Library of MFC are related to com, ActiveX control must bear the heavy burden of Runtime Library due to the nature of the inherited Implementation of MFC. If you use the static connection to the MFC Runtime Library, the ActiveX Control Code will be too large and will occupy valuable network bandwidth resources during network upload and transmission; if you dynamically connect to the Runtime Library of MFC, the browser must have the Runtime Library support of MFC. In short, MFC's support for COM technology is not flexible in the network application environment. Solving the problems in the above com development method is the basic goal of ATL.

The above is a brief introduction to ATL. In my blog a few days ago, I customized the leading tool of IE browser-BHO
We mentioned how to build your own browser and expand the browser functions. due to a recent project, the customer wanted to extract data from a set of national systems. We could not touch any function of that system, but simply add several pages or JavaScript Functions. however, we do need the system to provide necessary information to the current user who wants to mount the system. This system is a complete complement to the National Bureau system and integrates some auxiliary functions, provide audio and video evidentiary materials for auditors to check relevant data.

Therefore, in terms of technical implementation in the preliminary research, I thought of the BHO + ActiveX technology. The testing technology is indeed feasible. by clicking the relevant menu item we added in the webpage context menu, parsing by JavaScript

The data on the current page, and then call the ActiveX control to communicate with the central service program socket, send the collected information to the central server. If you do not know about the development of the ATL ActiveX control, you can first look at the vckbase

OnSimple example of developing and deploying ActiveX controls using ATLThis articleArticle(Developed using vs 2003), the example provided is very simple, with only one getstring (BSTR) method. for more details about control attributes, events, attribute dialog box programming, GDI rendering, script engine, and other development content, see instructor Yang.Plot the curve of any plane function using ATL ActiveXThe process of developing controls is still relatively smooth,

However, when compiling the real‑version, A libcmt. Lib (crt0.obj): Error lnk2001: unresolved external symbol _ main error occurs. The solution is also found on the Internet (

From Xiaofei's Baidu space article ).

"I recently wrote an ATL Project. In the end, I encountered this problem in realcompute. At that time, I was shocked. Later I found the problem. If the code is correct, the configuration was incorrect, because debug has no problems.
cause of error: This Link error occurs when the CRT function is used and the CRT startup code is required for these functions. Because the Preprocessor definitions in the release configuration defines _ atl_min_crt, it deletes the CRT startup code from the DLL.
the simplest way is to delete _ atl_min_crt in the project settings, but this will increase the size of the compiled file. Or enter libcmt. Lib in the ignore libraries set in the project. When you re-connect, you will get several "unresolved external" errors, and then you will start to look for things that you think may be pulling in the startup code and remove them if you can. instead, use their Win32 equivalents. for example, use lstrcmp () instead of strcmp (). known functions that require CRT startup code are some of the string and floating point functions.
Read Microsoft's document.
ATL supports optimizing a server to a minimum size or a minimum dependency. We can define three pre-processor symbols to affect server optimization.
_ atl_min_crt server does not link to the Standard C/C ++ Runtime Library
_ atl_dll Server Dynamic Link tool library ATL. DLL
_ atl_static_registry server static link support for component registration

If the Preprocessor symbol _ atl_min_crt is defined, the C/C ++ Runtime Library is not linked, and ATL provides an implementation of the functions malloc, realloc, new, and delete. When this symbol is defined, no other C/C ++ Runtime library functions can be called.
The ATL project generated by the ATL wizard defines _ atl_min_crt for all release versions, but this symbol is not defined for the debug version.
The debug configuration does not define any of the three symbols.
The relminsize configuration defines _ atl_min_crt and _ atl_dll.
The relmindependency configuration defines _ atl_min_crt and _ atl_static_registry.
I vaguely remember that VC's SP6 did solve this bug, but I was still lazy and didn't play servicepack6 for VC. You can also open stdafx. cpp and comment out # include <atlimpl. cpp>.
Msdn description
Info: lnk2001 error ATL release build
ID: q165076



--------------------------------------------------------------------------------
The information in this article applies:

Microsoft Active Template Library, versions 2.0, 2.1, 3.0

--------------------------------------------------------------------------------


Summary
Microsoft Active Template Library com Appwizard generates a release build of your project using macro _ atl_min_crt. selecting this configuration causes the C run-time (CRT) Library startup code to not be linked into your project. if you use functions or code in your project that require the use of the C run-time library startup code, you may experience lnk2001-unresolved external errors when you try to build the release version of your project.



More information
You can use some C run-time functions without requiring the CRT startup code. examples include the mem * functions. other functions require the CRT startup code. CRT string comparisons for example require the startup code as the CRT initializes some tables used for comparing. global objects that have constructors also require the startup code. in Visual C ++ 5.0, statically linking the startup Code adds about 25 K to your image (in Visual C ++ 4.2 It is about 20 K ).

Following are some suggestions for finding the cause of the lnk2001 errors:

In the linker options there is an "ignore libraries" edit box. enter libcmt. lib into it, and build. you get several unresolved externals. this list is everything that you are using from the CRT. look for things that you think may be pulling in the startup code and remove them if you can.


Don't ignore libcmt. Lib, but turn on the verbose flag for the linker. From this, you can see what is triggering CRT startup code to get pulled in.


If you decide that you really need the startup code, then remove the _ atl_min_crt define from the Project Settings. you can also dynamically link to the CRT, which reduces your image size but requires the CRT's DLL. if you turn on Exception Handling you have to pull in the startup code. even when building minsize the default is to statically link to the CRT and use _ atl_min_crt."

Finally, it is worth mentioning that the biggest problem of ActiveX is browser security restrictions, which are generally not allowed to be executed. Therefore, the customer's computer needs to reduce the security of specific websites, of course, the best way to handle is to control

Sign the certificate and identify it as a security control. fortunately, as long as you direct the URL of the right-click menu item to the relevant page on the central server, you only need to register the DLL of this control on the central server, and then forward the data to the return visit.

Ask the client to notify the client program on the client to respond accordingly. to solve this problem, we mainly integrate all the functions into its original B/S for interactive operations, taking into account the user experience.

Convenience. Of course, we can ask the user to input the relevant data on the page to the interface provided by our system for video query playback and other related operations, but in terms of user usage, the operability is not very good.


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.