PHP4調用自己編寫的COM組件

來源:互聯網
上載者:User
搞完了PHP4調用JavaBean,又想去試試調用COM,開始以為很難,自己用VB6寫了一個Active Dll在PHP4中調用,馬上成功,比調用javabean方便多了,下面講一下我的步驟。

一:用VB6寫Activex Dll

代碼如下:

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 = 1

If num = 0 Then Get_Number_Attrib = 0

End Function

具體方法如下:建立一個VB6工程,ActiveX Dll將工程命名為P_test,類名為c_test

類的檔案內容如上。

編譯產生p_test.dll檔案

二:註冊

提示符下運行:regsvr32 p_test.dll

三:編寫php檔案,test.php4代碼如下:

<?

$b=new COM("p_test.c_test");

$a=$b->Test_Number(-454);

echo $a;

?>

運行php4檔案將顯示-1

可能遇到的問題是,編譯工程時通不過,要將

Microsoft Active Server Pages Object Library

引用進來,具體實現“Project->References”找到改庫,並勾上

相比之下,PHP4調用com應該比PHP4調用javabean好哦,因為畢竟是Ms系統嘛。大家也可以去自己編寫調用資料庫的控制項,用PHP4調用,從某種程度上,和PHP調用javabean一樣,可以說,實現了“隱藏原始碼”。



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

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

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