您的位置:首页 > 文档 > 编程技术 >
 文章分类 

PHP4调用自己编写的COM组件


创建:2005-10-28 00:00:00
作者:Unlinux
来自: http://www.Unlinux.com

PHP4调用自己编写的COM组件

搞完了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_t
est

类的文件内容如上。

编译生成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一样,可以说,实现了“隐藏源代码”。

转载自:http://www.unlinux.com/doc/program/20051106/7954.html

评论】 【加入收藏夹】 【 】 【打印】 【关闭
 *  请尊重我们的劳动,转载请注明出自UnLinux.Com及作者名 * 

※ 相关链接
 ·solaris7+php4.0.2+gd1.8.3+sybase12.0+apache1.3 安装手册  (2005-10-28 00:00:00)
 ·用PHP4 和 PostgreSQL 构建一个电子商务应用  (2005-10-27 22:52:26)
 ·RedHat9下apache1.3+php4+mysql4安装手记  (2005-10-27 22:05:08)
 ·Solaris 9 + MySQL + PHP4 安装过程  (2005-10-27 22:05:08)
 ·win2000+php4+apache2+mysql4+vbb安装手册  (2005-10-27 22:04:40)
 ·RedHat AS2.1下Apache2.0.49+php4.3.6+oracle9.2.0的安装  (2005-10-27 22:04:14)
 ·在Debian上配置Apache+MySQL+PHP4  (2005-10-27 22:04:01)
 ·apache+php4+mysql  (2005-10-27 22:03:31)
 ·不编译完全配置RedHat Linux7.1下的Apache、DB3、 GD、LDAP、Mysql、Php4、SSL  (2005-10-27 16:18:51)
 ·FedoraCore1上用纯rpm安装apache2/php4/mysql4  (2005-10-27 16:18:15)

Copyright © 2005 UnLinux.Com All Rights Reserved