如何用PHP调用自己编写的COM组件?

ZDNet软件频道 时间:2008-07-01 作者: | 中国IT实验室 我要评论()
本文关键词:调用 COM PHP Linux
 新建一个VB6工程,ActiveX Dll将工程命名为P_test,类名为c_test ,类的文件内容如下:
 首先写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"找到改库,并勾上 。

调用

COM

PHP

Linux


百度大联盟认证黄金会员Copyright© 1997- CNET Networks 版权所有。 ZDNet 是CNET Networks公司注册服务商标。
中华人民共和国电信与信息服务业务经营许可证编号:京ICP证010391号 京ICP备09041801号-159
京公网安备:1101082134