ASP 調用dll及封裝dll執行個體

來源:互聯網
上載者:User

開啟VB6,建立ActiveX DLL
2、在工程引用中加入Microsoft Active Server Pages Object Library選擇
3、填加代碼如下: 複製代碼 代碼如下:'Code Start
'聲明部分
Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session
'下面定義公用函數(在VB中訪問ASP對象,即在VB中可以用MyApplication等同於ASP中的Application、MyRequest等同於ASP中的Request、 MyResponse等同於ASP中的Response、 MyServer等同於ASP中的Server、 MySession等同於ASP中的Session 使用)
Public Sub OnStartPage(PassedScriptingContext As ScriptingContext)
Set MyScriptingContext = PassedScriptingContext
Set MyApplication = MyScriptingContext.Application
Set MyRequest = MyScriptingContext.Request
Set MyResponse = MyScriptingContext.Response
Set MyServer = MyScriptingContext.Server
Set MySession = MyScriptingContext.Session
End Sub
Public Sub OnEndPage()
Set MyScriptingContext = Nothing
Set MyApplication = Nothing
Set MyRequest = Nothing
Set MyResponse = Nothing
Set MyServer = Nothing
Set MySession = Nothing
End Sub
'建立自訂函數SayHello
Public Sub SayHello()
MyResponse.Write ("Hello World")
End Sub
'Code End

4、將類名改為:HelloWorld 將工程名改為:TestVBCode
5、產生TestVBCode.DLL檔案,並使用Windows運行註冊組件命令Regsvr32 路徑\TestVBCode.DLL註冊後即可使用。(卸載組件命令為Regsvr32 /u 路徑\TestVBCode.DLL)
6、建立Test.asp檔案,代碼如下 複製代碼 代碼如下:<%
'VB自建函數調用格式
'Set 對象名=Server.CreateObject("工程名.類名")
'對象名.自建函數名
Set MyTestObj = Server.CreateObject("TestVBCode.HelloWorld")
MyTestObj.SayHello
%>

7、運行Test.asp檔案結果顯示如下:
Hello World
===========================================================
對於更複雜的運用,大家可以通過這個執行個體向外擴充就可以了.
如: 複製代碼 代碼如下:Public Sub connstr2()
Set conn = MyServer.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & MyServer.MapPath("codata.mdb")
Set rs = conn.Execute("select * from news")
Do While Not rs.EOF
MyResponse.Write (rs("news_title") & "<br>")
rs.MoveNext
Loop
rs.Close
Set conn = Nothing
End Sub

這個是用資料庫連接的代碼封裝,當然這裡要添加ADO引用的.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.