VB编写DLL时关于“引用”的相关知识

前端之家收集整理的这篇文章主要介绍了VB编写DLL时关于“引用”的相关知识前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、ASP内部对象的“引用”

在Dll里,不能直接使用ASP的内部对象,要使用ASP的内部对象,必须引用“COM+ 服务类型库(Comsvcs.dll)”和ASP.Dll。如何访问Visual Basic COM组件内的Active Server Pages内部对象,详见:http://support.microsoft.com/kb/299634/zh-cn

也就是说,编写组件,如果在dll中使用Asp的内部对象——比如Response,Request,Session,Application,Server等,必须引用:

1、COM+ Services Type Library 即“COM+ 服务类型库(Comsvcs.dll)”
2、Microsoft Active Server Pages Object Library 对象库ASP.Dll

代码参考如下:

Private Response As Response
Private Request As Request
Private Server As Server
Private Application As Application
Private Session As Session
Private objContext As ObjectContext

Private Sub Class_Initialize()
  Set objContext = GetObjectContext()
  Set Response = objContext("Response")
  Set Request = objContext("Request")
  Set Server = objContext("Server")
  Set Application = objContext("Application")
  Set Session = objContext("Session")
End Sub

Private Sub Class_Terminate()
 Set ojbSContext = Nothing
 Set Response = Nothing
 Set Request = Nothing
 Set Server = Nothing
 Set Application = Nothing
 Set Session = Nothing
End Sub

二、使用ADO则必须引用 Microsoft ActiveX Data Objects 2.7 Library

代码参考如下:

'Conn 得到数据库连接对象  ADODB.Connection
Public Property Let Cls_GetConn(ByVal TmpDB As String)
 Set mmConn = New ADODB.Connection
 mmConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & TmpDB
End Property

' ADODB.Recordset
Public Sub Cls_Ins()
 Dim N
 mmsql = "SELECT * FROM " & mmTable
 Set mmRs = New ADODB.Recordset
 mmRs.Open mmsql,mmConn,1,3
 mmRs.AddNew
 For N = 0 To UBound(mmFieldsArr)
  mmRs(mmFieldsArr(N)) = mmValuesArr(N)
 Next
 mmRs.Update
End Sub

ADODB.Stream对象
Set mmOSM = New ADODB.Stream
If Err.Number = -2147221005 Then
  Response.Write "非常遗憾,您的主机不支持ADODB.Stream,不能使用本程序"
  Err.Clear
  Response.End
End If

三、使用FSO,则必须引用 Microsoft Scripting Runtime (FSO—Scrrun.dll)

代码参考如下:

Set mmFSO = New FileSystemObject
If Err Then
  Response.Write "<li>您的空间不支持FSO,或者没有相关权限,不能使用本程序。此错误描述如下:" & Err.Description & "</li>"
  Err.Clear
  Response.End
End If

四、其它

如果使用上下文环境,需要使用Microsoft Active Server Pages ObjectContext Object Library,主要是事务的使用,如setcomplete等等。一般来说,使用Microsoft Active Server Pages Object Library就够了,如果使用事务,可以使用ado的

原文链接:https://www.f2er.com/vb/259596.html

猜你在找的VB相关文章