1 。打開您的Microsoft Visual Basic:
點擊確定,以下就按照藍色的數字步驟.
2 。修改工程名和類模塊的名稱:
點3,把4改成bi,再點5:
6處改成cjjer.
3。增加到引用asp:
點擊引用,然后選擇其中的Microsoft Active Server Pages Object Library.
點9確定.
4。編寫代碼:
Option Explicit Private Context As ScriptingContext Public Sub OnStartPage(PassedscriptContext As ScriptingContext) End Sub End Sub ' 釋放內部對象 Set Context = Nothing
Private Application As Application
Private Response As Response
Private Request As Request
Private Session As Session
Private Server As Server
Set Context = PassedscriptContext
Set Application = Context.Application
Set Request = Context.Request
Set Response = Context.Response
Set Server = Context.Server
Set Session = Context.Session
Public Sub showsuc()
Response.Write "我是藍色理想的老農,您好"
Public Sub OnEndPage()
Set Application = Nothing
Set Request = Nothing
Set Response = Nothing
Set Server = Nothing
Set Session = Nothing
End Sub
其中,除10處,其他都是必須的.
10處是我們自己要表現的程序.
ctrl+s保存在d:\mylib\cjjer.cls
在把工程保存為d:\mylib\bi.vbp
5 。編譯,注冊成dll:
點擊生成bi.dll
沒啥警告的話那就ok了,路徑保存在d:\mylib\bi.dll.
然后開始--------->運行-->
regsvr32 d:\mylib\bi.dll
這就注冊成功了.
6。使用bi.dll:
新建asp文件,輸入:
<%
Dim bicjjer
Set bicjjer=Server.CreateObject("bi.cjjer")
bicjjer.showsuc()
%>
瀏覽器,預覽,顯示如下:
注意:對已經存在的組建名稱或這修改了dll文件,必須先停止IIS,再重啟注冊使用,否則會一直在原來的基礎上.
另外補充一點:生成的dll文件不注冊到服務器也可以使用:
<% @ language="vbscript" %>
<!--METADATA TYPE="typelib" FILE="e:\web\web\asp\bi\bi.dll"-->
<%
Dim bicjjer
Set bicjjer=Server.CreateObject("bi.cjjer")
bicjjer.showsuc()
%>
這絕對是個好消息,有人說這個沒什么價值,那我說"您還是固陋寡聞或者您技術高的藐視dll...",哈哈哈,當然是玩笑了,注意,METADATA的file路徑是絕對的物理路徑,否則無法裝載.