Write COM components for dynamic Web pages such as asp/php

Source: Internet
Author: User
Tags disk usage
ASP, PHP and other Dynamic Web language features are very powerful, but COM can make it a power. In fact, we usually use ADO, FSO, JMail, and so on is COM. With Com,web, you can invoke almost all of the functionality of a local application to feed back to the page. For example, query server disk usage, CPU utilization, and finally I will say a few non-mainstream ideas.

The development of COM tools is the development of EXE application tools, VB, VC, Delphi can be. But VB has a natural advantage, a few lines of code can write COM. In VB, COM is also called an ActiveX DLL. The following is a very simple example of whether the year is leap years.

Create a new ActiveX DLL project, the project name is Checkyear, and the automatically generated class name is Leapyear. Write down the following code:

Option explicitpublic Function isleapyear (yr as Variant) as Boolean    If yr mod 4 = 0 and yr mod <> 0 then IsL Eapyear = True Else isleapyear = FalseEnd Function

Well, it's a little bit too simple to adapt. So COM is done, build the DLL. then register it. Enter "regsvr32 H:\checkyear.dll" in the run. If you have IIS or Netbox in this rack, you can call it on the ASP Web page. If it is for a server, the above thing needs to be done on the server. The ASP calling code is as follows:

<% Option Explicitdim ocheckyear,sdim year, Isleapyearyear=2004set ocheckyear=createobject ("CheckYear.LeapYear") Isleapyear=ocheckyear.isleapyear (year) Set ocheckyear=nothing%><% If isleapyear=true then s= "is a leap year! "Else s=" is not a leap year! "%><%=year%> Year <%=s%>
COM can also be called in EXE application development tools. When writing complex COM, they can be used to detect features. After COM registration, you can see it in the References list in VB. For example, the following is the code that VB calls it:

Private Sub Command1_Click ()    Dim c    Set C = CreateObject ("Checkyear.leapyear")    Dim D As Boolean    d = C.isle Apyear (2004)    MsgBox DEnd Sub


COM opens an infinite possible door, and the following is what you play. Kingdee, UF and so very good use of such methods. Let's talk about my non-mainstream usage. WebService must have used, many portals or manufacturers to provide free webservice way of weather, stock market and other information. We can access it directly using the URL in the program. Here to say is a non-public, informal "service", that is, the IP138 website provides the IP information query page, http://iframe.ip138.com/ic.asp, it returns simple IP and location information, such as "Your IP is: [17.89.9.11] From: Guangdong province Shenzhen Telecommunications ". In my program, I ask for information to query the user's location, which is more convenient than checking the database, and it claims that its address is always up to date. This can also be used in COM, on the page as long as the call to the method provided in COM can be. Someone asked: Does this always get the server's address information? So we're going to use winhttprequest to build our own packets. The page passes the user IP into the com,com and then constructs the user IP in the packet and sends it to IP138. The method of sending VB has inet control and XMLHTTP, more detailed content of their own Baidu.

  

  • 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.