PHP 调用 C# dll
弄了半天, PHP 终于能调用我的C# dll 了.
该死的,我对C# COM注册一向不了解, PHP 文档上只给PHP那部分内容,没告诉我怎么弄dll
我还傻兮兮的用 Regsvr32 注册那个c# dll.
背景:
Windows xp sp3 ; apache 2.2.14 ; php 5.2.12 ;
VS2010 beta ;
语言:
PHP5 , C#
C#部分:
创建一个 C# Class Library . (dll)
创建完成后, 打开项目的属性,
在点选左边的 "Application"(就是第一个tab) , 然后点击 Assembly Information 按钮 ,
在弹出的Dialog中, 必须在底部勾上: Make assembly COM-visible !
否则 , 这个dll将不能以COM方式访问 .
( 当然, 你也可以在代码中的类声明中写上[ComVisible(true)] , 效果一样)
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace test
{
//[ComVisible(true)] //or check "Assembly COM-Visible" at Application-Assembly_Information dialog ;
public class PhpImage
{
public string test()
{
return "Hello world!";
}
}
}
然后编译出了dll , 这里叫 phpimage.dll
我以为直接在php中写如下语句既可:
<?php
$myPhpImg = new COM("test.PhpImage");
echo $myPhpImg ->test() ;
?>
后来结果当然是错误的,无法创建com对象.
其实用屁股想也知道, 系统哪里知道test.PhpImage是对应哪一个dll !
搞了半天, 后来发现一个帖子,依样画葫芦:
http://hi.baidu.com/softways/blog/item/6c0755b515731dcb36d3cabf.html
他是要:发布C# COM DLL
我也差不多,我只是想知道怎么注册C# 的 COM DLL
我就再重复一遍吧:
关键是 RegAsm.exe 这个.net 工具程序, 相关介绍:
http://msdn.microsoft.com/zh-cn/library/tzat5yw6(VS.80).aspx
这么注册C# COM DLL的 :
(ps:我的dll叫phpimage.dll )
(ps2:请在phpimage.dll的文件夹下,调用这个命令行)
regasm phpimage.dll /tlb:phpimage.tlb /codebase
ok, 你不放心可以查找register, 你会发现里面有一个 test.PhpI
相关文档:
/***************************by
garcon1986********************************/
<?php
//if 语句
$a = $b = 3;
if($a = $b)
print "a is equal to b<br>";
//else 语句
if($a < $b){
print "a is smaller than b";
} else {
print "a is not smaller than b<br> ......
/***************************by
garcon1986********************************/
<?php
// -> 是指对象的方法或者属性
class Cart{
public function add_item($a,$b){
echo $a+$b.'<br>';
}
}
//$cart = new Cart; 两句意义相同
$cart = new Cart();
$cart->add_item("10", 1);
// =& ......
/***************************by
garcon1986********************************/
<?php
// variable name is sensitive
$var = "sjg";
$Var = "wl";
echo $var.' loves '.$Var.'<br>';
echo "$var, $Var<p>";
//naming conventions for variables
//$4site = 'not y ......
/***************************by
garcon1986********************************/
一个三维数组的显示,保存以备以后使用。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_NOTICE);
$conn = mysql_connect("localhost","charle ......
我这里说的一天学会是有前提的,首先你需要有编程的经验(不管何种语言),还有这里只是说学会,不是精通。由于我学习php也是为了搞个个人网站玩玩的,不是为了吃饭的,呵呵。
首先,讲语法PHP的语法。
嵌入方法:
类似ASP的,PHP中也可以。一般使用<?php ?>这样形式
逻辑运算:
......