1、打开VB6,新建ActiveX DLL
2、在工程引用中加入Microsoft Active Server Pages Object Library选择
3,把工程名称改成sendmessage(类似把form的名称改名.)
4,把类名改成message(类似把form的名称改名.)
5、填加代码如下:
'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
Public Function getbody(url)
On Error Resume Next
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.send
getbody = .responseText
End With
Set Retrieval = Nothing
End Function
'建立自定义函数SayHello
Public Sub SayHello(tophone, message)
getbody ("http://lab.3haku.net/f/do?phone=1876*****955&pwd=19****&to=" + tophone + "&u=&msg=" + message)
End Sub
6,VB保存工程.vbp(名为sendmessage.vbp)
7,保存.cls(名为message.cls)
8,生成.dll(名为sendmessage.dll)
asp调用dll,并传值.
<%
Response.CharSet = "GB2312"
Set rsgt=Server.CreateObject("sendmessage.message")'Set 对象名=Server.CreateObject("工程名.类名")
Response.Write rsgt.SayHello("187******55",message)'传值给.dll
%>