首页 > 开发 > PHP > 正文

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

2024-05-04 22:59:30
字体:
来源:转载
供稿:网友
首先写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"找到改库,并勾上 。

收集最实用的网页特效代码!

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