首先寫ActiveX Dll:
新建一個VB6工程,ActiveX Dll將工程命名為P_test,類名為c_test ,類的文件內容如下:
Option Explicit
Private MyscriptingContext As scriptingContext
Private MyApplication As Application
Private MyRequest As Request Private MyResponse As Response
Private MyServer As Server
Private MySession As 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 Test_Number(num) As Variant
If num 0 Then Get_Number_Attrib = 1
If num = 0 Then Get_Number_Attrib = 0
End Function
編譯生成p_test.dll文件
注冊
提示符下運行:regsvr32 p_test.dll
編寫php文件,test.php4代碼如下:
<?php
$b=new COM("p_test.c_test");
$a=$b->Test_Number(-454);
echo $a;
?>
可能碰到的問題是,編譯工程時通不過,要將Microsoft Active Server Pages Object Library引用進來,具體實現"Project->References"找到改庫,並勾上 。