ActiveX component compilation and ASP interface application
ActiveX
ActiveX is Microsoft to enable developers to integrate the computer desktop environment with an environment that forms the Internet and a large number of resources, while protecting existing development investment in windows. ActiveX includes a series of extensions and enhancements to two existing Microsoft technologies: Win32 API and Component Object Model (COM), object link and Embedding (OLE) an application is constructed based on it.
ActiveX components refer to executable code, such as A. EXE,. dll, or. ocx file. They follow ActiveX specifications when providing objects. With ActiveX technology, programmers can assemble reusable software into applications or service programs.
ASP
ASP is the scripting environment on the server. You can use it to create dynamic web pages or generate powerful web applications. ASP pages are files that contain HTML tags, text, and script commands. You can call ActiveX components to execute tasks on ASP pages.
Create and register ActiveX Components
You can create ActiveX components for a large number of Internet and Intranet advanced applications. Now you can use an instance to create, register, and use ActiveX components on ASP pages.
Programmers can develop ActiveX Components in any language that supports automation. When selecting a program language, consider the degree of familiarity with the language, tool support, runtime performance, thread model, Code complexity, and size of compiled code. Languages and products that can be used to compile automation components include Microsoft Visual C ++, Microsoft Visual Basic, and Java. The examples used in this article are written in Microsoft Visual Basic.
ASP itself also has several embedded ActiveX components, including the file access component, but it is generally only used for reading and writing files on the client side. To read and write files on the server side, you need to grant the write permission to the web site to the WINNT server's Internet anonymous access account iuser_xxxx (the host name of WINNT server after the underline), which causes a system security vulnerability. By creating a server-side ActiveX component that reads and writes specific files, you can ensure system security.
The following describes how to compile ActiveX Components in Microsoft Visual Basic 5.0:
1. Open Microsoft Visual Basic 5.0 and select "ActiveX dll" in the new project window (figure 1 );
2. Select "add class module" in the toolbar to add classes, attributes, and methods (figure 2 );
3. You can name and set attributes for the newly added class module. The ActiveX component class in this article is as follows. Note that the instancing attribute of the filetext class is set to "5-multiuse" (Figure 3 );
4. you also need to provide the ActiveX component with a client call portal, select "add module" in the toolbar, and enter an empty main () the process serves as the interface for the customer to call (figure 4 );
5. Set the project name to "Stone". Note: The project name plus class name "Stone. filetext" is the "progid" of the ActiveX component that will be called in ASP later ";
6. Select "file generation filetext. dll" in the menu and compile the file as a DLL file (figure 5 );
7. put filetext. copy the DLL file to the "C: \ winnt \ system32 \" path and execute "C: \ winnt \ system32 \ regsvr32 filetext. DLL "to register this DLL file in the WINNT registry. After that, you can find in the WINNT registry that the classid of the "Stone. filetext" component is "{Your bde6c-d38f-ba80-00your b27c01d}", indicating that the component has been correctly registered.
Call the self-made ActiveX component on the ASP page
Use the following two methods to call the above components on the ASP page:
A. Static call
Use HTML standard tags: <Object> and </Object>, for example:
<Object
Id = ft
Classid = "CLSID: rjbde6c-d38f-ba80-00417b27c01d"
Width = 1
Height = 1
Align = left>
Then, several methods of this ActiveX component can be used in ASP statements;
B. Dynamic call
Use the Createobject () method of ASP Embedded Server Object:
<%
Set Ft = server. Createobject ("Stone. filetext") 'creates an instance of a component (that is, an object)
Curpath = server. mappath ("SMS /")
'Obtain the WINNT real path of the virtual path "SMS /"
Curpath = curpath & "\" & rs_movie ("link_filename") 'to obtain the full path
Ft. openreadtext curpath, 1
Use the openreadtext method of the stone. filetext component
'Open a file
%>
Conclusion
Through the above example, you can see that ActiveX components are the most effective method for implementing application functions on the Internet/Intranet. Readers can try to use ActiveX and ASP to develop many complex application functions. You can obtain many powerful free ActiveX components and ActiveX controls from the following URLs for research and reference:
It is very convenient to develop ActiveX controls using vc6.0. The following is an example of helloword:
Open vc6.0, create a project, select MFC ActiveX controlwizard, and enter the project name ),
Select the project path and click OK.
On the first property page, you can set several controls for this project, such as whether to add a running license to the control, and keep the default settings. Click Finish.
ActiveX control runs in the container. If you want to test the project in vc6, you can click execute. The system will prompt you to view the specified execution file,
Find this file: Microsoft Visual Studio \ common \ tools \ tstcon32.exe and open a window to test the ActiveX control.
Click Edit. Insert new control, find your control, and quickly display the name of your control.
To call ActiveX methods in an external program, release the Methods:
Click View. classwizard, select the automation tab, and click Add method to add a method helloword.
If the external name is good, the internal name is helloword.
To call the ActiveX control in IE, you must register it in the registry. After compiling the link, the system automatically writes the registry information. You can also manually register it yourself,
The command is regsvr32. To register a self-written control, you only need to write it in the running dialog box: regsvr32 *. ocx indicates that the operation is successful. Add the-u parameter to the anti-registration.
After registration, you can find the control you have registered in the registry, open the Registry Editor In regedit, and use the control name to find the control,
Copy the CLSID and use this ID for network calling.
Create an HTML file and load the control first:
<Object ID = "myocx" classid = "CLSID: E5CB2C66-66E1-4FFD-81D7-08B08BFB8D65"
Codebase = "C: \ Program Files \ Microsoft Visual Studio \ myprojects \ test1 \ debug \ hello. ocx"> </Object>
Then you can write a JS function to call the method in the control:
<SCRIPT type = "text/JavaScript">
Function sayhello ()
{
Document. getelementbyid ("carder"). sayhello ();
}
</SCRIPT>
To load the DLL in ocx, place the DLL file in the c: \ windows \ system32 folder. Otherwise, the file cannot be found.
In fact, the OCX control is a standard control, which is used for Vb/VC development. It can be called wherever it is (under the win platform ). with InterDev, you can easily embed OCX into ASP. You can drag and drop the mouse to directly modify attributes.