上次继本人发布了VC编写PHP扩展之Hello World篇后,反映很强烈,大家都希望能脱离PHP菜鸟行列,这次我给大家带来PHP调用C#编写的COM+组件。
COM+组件源代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Data.OleDb;
using System.Data;
using System.Collections;
using System.Collections.Specialized;
namespace comtest
{
[Guid("DE03FB14-23D6-4be0-93EA-C27651A22A37")]
public interface ITest
{
string Test(string test);
[DispId(0)]
string About();
[DispId(1)]
int Add(int a, int b);
}
[Guid("0ED3C99A-6EBB-4df5-B03F-16CACE242C67")]
public class Class1 : ITest
{
public string Test(string test)
{
return test;
}
public string About() { return "欢迎访问 http://www.sojqi.com"; }
public int Add(int a, int b) { return a + b; }
}
}
以上代码编译后生成 comtest.dll 然后将其注册
php调用
<?php
$b=new COM("comtest.Class1");
$t1=123;
$t2=456;
$r=$b->add($t1,$t2);
$f=$b->about();
echo $r;
echo $f;
?>
[ 本帖最后由 lyxcf 于 2008-5-4 11:27 AM 编辑 ]