当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP4调用自己编写的COM组件

PHP
MYSQL版本大于4.1问题 - PHPchina
怎么让用户点击一个连接后,把一个图片另存了 - PHPchina
武汉10月15日Phper聚会召集!!! - PHPchina
php如果不等待exec执行的程序创建的子进程? - PHPchina
哪位知道DISCUZ处理防SQL注入的代码是哪部分 - PHPchina
求教!我实在不知道哪里问题,在线等ing - PHPchina
怎样结束用户某一进程 - PHPchina
比对用户名密码能不能这样写? - PHPchina
求助:如何在PHP+mysql中实现数据备份? - PHPchina
大家看看这个配置对吗 - PHPchina
如何禁止require当前文件 - PHPchina
无法将回调函数放在类中? - PHPchina
村里 PHP代码高亮是怎么实现的? - PHPchina
apache安装后.服务里没有apache2这个服务! - PHPchina
请教一个小问题 - PHPchina
config.php里面是不是应该把多数参数设置为常量而不是变量? - PHPchina
请教高手一个问题 - PHPchina
如何让百度收录我的网站 ?? - PHPchina
谁能给个注入的简单语句? - PHPchina
求PHP站内搜索思路 - PHPchina

PHP4调用自己编写的COM组件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 132 ::
收藏到网摘: n/a

      
  
  
  搞完了PHP4调用JavaBean,又想去试试调用COM,开始以为很难,自己用VB6写了一个Active Dll在PHP4中调用,马上成功,比调用javabean方便多了,下面讲一下我的步骤。
  
  下载的版本是从http://www.mm4.de/。
  
  一:用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一样,可以说,实现了“隐藏源代码”。
  
  欢迎有兴趣的朋友交流。