I. Overview
In the following section, we will briefly introduce the concept and classification of ActiveX components, so that readers can have a conceptual grasp of ActiveX components. The following describes how to register ActiveX components. The registration methods of ActiveX controls, ActiveX DLL, and ActiveX EXE are provided respectively. On this basis, how to installProgramAfter installation, some solutions are provided for registering ActiveX components.
Ii. Concepts of ActiveX Components
in our usual reading and programming studies, we often see terms such as "ActiveX controls" and "ActiveX components. So what are "ActiveX controls" and "ActiveX components"? What are their differences?
first, we should know that components are independent units of Code built on ActiveX technology, it is used to provide a specific set of services through a specific interface. It provides the Objects requested by the client at runtime. In remote data service, when a component includes a keyword logic that supports business processes, it is also called a "Business Object ".
ActiveX is an encapsulation technology that enables software components to interact in the network environment and is independent of the language used to create components. The basis for ActiveX implementation is "Component Object Model" (COM ). It is also a method that encapsulates COM components and places them into applications (such as (but not limited to) Web browsers.
at last, the COM (Components Object Model) mentioned in the above section is a way for software components to communicate with each other. It is a binary and network standard that allows any two components to communicate with each other, regardless of the computer on which they are running (as long as the computer is connected ), no matter what operating system the computer runs (as long as the operating system supports COM), or the language in which the component is written. Com also provides location transparency: When writing components, other components, such as in-process DLL, local EXE, or components on other computers, will not have a big impact.
in this way, we can define ActiveX component (ActiveX component) as an application or development tool that can use objects supported by another application, or provide your own objects for another application. Previously, these programs and objects were called "Ole auto service programs" and "Ole auto server ".
ActiveX controls are only a classification of ActiveX components and are a standard user interface element. ocx file extensions or objects that can be inserted can be quickly assembled into forms and dialog boxes. When a custom control dialog box is used to add it to a project, the toolbox will be expanded. Previously, ActiveX controls were called Ole controls. ActiveX controls also make the Internet more vivid, adding interesting new features for World Wide Web pages.
Iii. ActiveX Component Classification
ActiveX components can be divided into three types:
● ActiveX Control
● ActiveX document
● Code component (OLE Automatic server)
(1) ActiveX Control
It can be fully created by users from scratch. It can be built on another control, or it can accommodate existing controls. For example, ActiveX controls in VB are built on user control objects in VB. When creating an ActiveX control, a control class file with the extension. CTL is created. We usually use this file to create the actual control with the extension. ocx.
(2) ActiveX document
Generally, in a specific programming environment such as VB and VC ++, you can use the semantics of traditional documents to create a complete application. In other words, it not only has application functions, but also has the flexibility of document performance-when a user opens an ActiveX document, it not only has all the functions of the application, in addition, it can maintain and publish the "backup" of the original data of the application. Therefore, the "document" is actually active. For example, the ActiveX document of VB is based on the user document of VB. When creating an ActiveX document, save it with a file with the extension. DOB. VB uses this DOB file to create an EXE or DLL file. This EXE or DLL file can provide actual code for the activex file. In addition, VB generates a description file with the extension. vbd, which describes ActiveX documents and can be opened by the main application. ActiveX documents allow users to save data, which is stored in the vbd file.
(3) code Components
Previously called OLE Automatic server. These objects allow users to use their code in other programs. For example, there is a clock routine displayed in the Code component, so that this routine can be used by other programs. The Code components (ActiveX EXE and ActiveX DLL) Support attributes and methods.
4. Create ActiveX component selection
ActiveX components have different applications. So how to choose and determine whether to create the component?
First, we must understand the running mode of ActiveX components and the corresponding features. Generally, ActiveX components run in two ways: external server running and In-process server running.
If you use an ActiveX component as part of an executable file (exe file), it is an out-of-process server and runs in its own process. If it is used as a part of a dynamic link library (DLL file), it is an in-process server and runs as a client application in a unified process. If your ActiveX component is an out-of-process server, it is an EXE file that can be run independently. Applications using an in-process server usually run faster than those using an out-of-process server because the application does not use object attributes, methods, and events through process boundaries.
If the created ActiveX document is used as an in-process component (DLL file), the performance of the In-process component exceeds that of the component that is also compiled into exe. In addition, if multiple programs access the same EXE file, the global data will be overwritten; if they all have their own in-process servers, this will not happen.
The client application and internal process components share the same memory space. Therefore, when debugging the method of the internal process code component, you can use the client application stack to input parameters. For external process components, in the process of debugging code components, method parameters must be moved to pass the memory boundary between two processes. This is called external aling.
In this way, we can draw the following conclusions about how to select the created component type:
(1) To create an invisible component that provides routines in callable code, you can create a code component (ActiveX EXE or ativex DLL ).
(2) If you want to create a component that can run the program with the application in the same process, you can create a ativex DLL.
(3) If you want to create a component that can serve multiple applications and run on a remote computer, you can create a ativex exe.
(4) If you want to create a visual component and be dragged to an application during design, you can create a ativex control.
(5) to create a visual component and accept an application window at runtime, you can create an ActiveX document.
For details about how to program and use components after they are created, refer to related programming books. Here, we assume that the design of ActiveX components has been completed, and then we will discuss in detail the registration of ActiveX components.
V. Methods for registering ActiveX Components
Different ActiveX components have different registration methods. Now we provide solutions for ActiveX controls, ActiveX DLL, and ActiveX exe.
1. ActiveX Control registration
ActiveX control is independent of the development platform. Programming Language ActiveX controls developed in can be used in another programming language without any modification. However, after the ActiveX control is developed, to be correctly used in Windows, you must first copy the control file to the hard disk and then register it in windows. ActiveX controls that have not been registered in Windows cannot be used. Generally, you can register the VB6.0 ActiveX control using the following methods:
(1exe use the regsvr32.exe program to register the VB ActiveX control. The file is located in the system subdirectory of the Windows directory. The usage is as follows: click "start", click "run" in the pop-up menu, and enter the following command in the displayed dialog box:
<Control path and ActiveX Control File Name> register an ActiveX control. The path name of regsvr32 can be omitted here. In addition, the registered ActiveX control can be copied to \ WINDOWS \ SYSTEM, so that we do not need to enter the control path during registration.
To cancel registration of an ActiveX control, you only need to add the parameter "/u" after regsvr32, that is, <name of the registered ActiveX Control File>.
(2) Use browsing functions in some programming environments. For example, in VB6.0, you can click "project" on the interface and click "parts" in the drop-down menu. A new interface is displayed. On this interface, use the "Browse" button to find and select the control to be registered, and then register it in the "control" column of the "parts" interface.
After the preceding two methods are used to register a widget, the component developer can use the widget in actual programming.
(3) Use the installer to create the software-InstallShield. You can use the regsvr32.exe program to register ActiveX controls and use "Browse" to register ActiveX controls. Although simple, you must manually register them. when not in use, you must manually remove them, therefore, it is not practical for an application that uses the control. Generally, a large application requires an installer. It is very practical to solve ActiveX Control registration in the installer. You can use InstallShield to create Professional-level installation programs and register ActiveX controls. When you uninstall software, you can automatically cancel previously registered ActiveX controls. The installation program is created according to the InstallShield wizard. In the last step, click "finish" and "InstallShield" will perform "Detailed Customization" next ". Select the "file groups" option and change the "self-registered" attribute that includes the ActiveX control file item to "yes ".
(4) self-registration during installation. ActiveX controls must be registered during installation and can be called in applications. This goal is often achieved by using the installation and production tools that come with programming tools. Take VB6.0 as an example. Use the package & Deployment wizard tool that comes with VB6.0 to create the installer. As long as the ActiveX control is included in the middle of the published file, package & Deployment Wizard will automatically compress the control into the property of the Self-registered file as needed. If the installation fails, you can modify setup. lst in the installation file list. Set the parameters in the corresponding macro to dllselfregister. If you do not need self-registration, you can delete this item (note that you need to keep it with commas ).
For example, the following is an ActiveX Control compiled by the author. After the installation program is created using the above method, the following parameters change:
[Setup1 files]
File1 = @ clock1.ocx, $ (winsyspath), $ (dllselfregister), $ (shared), 2/19/01 9:27:30 AM, 36864, 1.0.0.0
The bold $ (dllselfregister) indicates the self-registered macro parameter settings. You can add or delete them manually.
(5) add one point. ActiveX Control registration developed by some companies requires the use of specialized tool software. Run the tool to register the ActiveX control. This is still a manual registration. When these ActiveX controls are released, they are generally copyrighted and have special instructions.
2. Register ActiveX DLL
The registration of ActiveX dll is basically similar to that of ActiveX control. The above methods for registering ActiveX control are basically applicable to the registration of ActiveX DLL. You can refer to the preceding Method for registering ActiveX controls.
3. Register ActiveX exe
As an out-of-process running component, the Registration Method of ActiveX EXE is different from that of ActiveX Control and ActiveX DLL, and it is difficult to use. Here, their registration methods are summarized as follows:
(1) "Browse. Take VB6.0 as an example. On the VB6.0 programming interface, go to "project", select "Reference" in the pop-up drop-down menu, and click "Browse" on the New Territories page that appears ", find and select the component to be registered. After confirming, you can see the corresponding item in the middle of the list.
(2) direct running method. When registering an out-of-process component ActiveX EXE, you only need to run the component code in the VB6.0 environment to implement registration. In this case, ActiveX EXE information is added to the Windows registry. However, you must note that this information is only temporarily added when running this program in the VB development environment. When the program stops, information about how to access these objects is removed from the system.
(3) Use the installation and production tools. For example, in VB6.0, you can use the package & Deployment wizard tool that comes with VB6.0 to create the installer. During the creation of the installer, it is automatically changed to self-registration. Otherwise, you can also modify setup. lst in the installation file list of the installer. Set the parameters in the corresponding macro to exeselfregister. If you do not need self-registration, you can delete this item (note that you need to keep it with commas ).
For example, the following is an out-of-process component compiled by the author. After the installation program is created using the above method, the following parameters change:
[Setup1 files]
File1@commthread.exe, $ (winsyspath), $ (exeselfregister), $ (shared), 12/25/00 8:47:44, 57344, 1.0.0.0
The bold $ (exeselfregister) indicates the self-registered macro parameter settings. You can add or delete them manually.
(4) If you want to install an out-of-process server on another machine for self-registration and exit the programming environment, you can first copy the file to another machine, add the parameter "/regserver" to the command line during execution. If the registration is canceled, add "/unregserver" to the command line ". When you use the/regserver Command Option to register a COM server outside the process, you can ignore the normal way in which the program works during manual startup. The sub main or class_initialize program will not be called and will run only when this programming environment includes the registration logic in the EXE file.
Vi. Summary
the above briefly summarizes the concepts related to ActiveX Components in daily learning. In terms of registration, some practical methods are provided. Of course, we can also compile some small programs by ourselves to register ActiveX controls. For example, in VC ++, use the Windows API function loadlibrary to load the ActiveX control, and then use the getprocaddress function to obtain the dllregisterserver (the deregistering function is the dllunregisterserver pointer) in the ActiveX control; finally, call the registration function dllregisterserver (or the logout function is dllunregisterserver ). If you are interested, you can start programming by referring to relevant materials.
of course, self-registration is often required in actual programming applications. ActiveX controls and ActiveX dll can be automatically registered after installation. However, ActiveX EXE may be troublesome, and we cannot
register it in the programming environment through code compilation or browsing every time you run the software. Through practice, the following methods are summarized to achieve self-registration:
(1) use the tool that comes with the programming tool to create the installation program. During installation, activeX EXE self-registration is automatically implemented.
(2) Add the parameter/regserver to implement self-registration. In VB6.0 programming, when ActiveX EXE is required, the system function shell () of VB6.0 is used for both calling and self-registration. Command Format:
shell "[path \] filename/regserser"
when uninstalling, you only need to replace/regserser with/unregserser. If the component file and the application are in the same directory or under \ WINDOWS \ SYSTEM \, the component file path name can be omitted.
(3) if you want to use InstallShield to create Professional-level installation programs for your applications and require self-registration of ActiveX EXE, you can use InstallShield to package the applications, activeX EXE is packaged with VB6.0 to generate two installation programs. During use, both the installation programs run once, which can also meet the requirements, but it is more troublesome