如何用PHP調用自己編寫的COM組件?

來源:互聯網
上載者:User
首先寫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 = 1
  If num = 0 Then Get_Number_Attrib = 0
  End Function
  
  編譯產生p_test.dll檔案
  
  註冊
  
  提示符下運行:regsvr32 p_test.dll
  
  編寫php檔案,test.php4代碼如下:
  
  <?
  $b=new COM("p_test.c_test");
  $a=$b->Test_Number(-454);
  echo $a;
  ?>
  
  可能遇到的問題是,編譯工程時通不過,要將Microsoft Active Server Pages Object Library引用進來,具體實現"Project->References"找到改庫,並勾上 。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.