首页 > 开发 > PHP > 正文

PHP4调用自己编写的COM组件

2024-05-04 22:54:45
字体:
来源:转载
供稿:网友
  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • 搞完了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一样,可以说,实现了“隐藏源代码”。

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表