我正在使用带有ASP.NET 2.0的C#.NET DLL,现在它正在运行。我想在PHP中使用相同的DLL。
我是PHP的新手;有人请告诉我如何在PHP中使用它或者你能分享一些例子吗?
答案 0 :(得分:9)
PHP有built-in Windows-only extension called DOTNET,允许您在PHP应用程序中使用.NET库。
请注意,您需要确保将程序集声明为COM可见:
[assembly: ComVisible(true)]
以下是两个例子。
<?php
$stack = new DOTNET("mscorlib", "System.Collections.Stack");
$stack->Push(".Net");
$stack->Push("Hello ");
echo $stack->Pop() . $stack->Pop();
?>
另一个展示DOTNET类功能的例子:
<?php
$full_assembly_string = 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a8425bc35256e463';
$full_class_name = 'System.Windows.Forms.Form';
$form = new DOTNET($full_assembly_string, $full_class_name);
// code to add buttons, menus, text, etc
$form->Show();
$form_event = '';
while($form_event !== 'close') {
// handle form functions and events
}
?>
答案 1 :(得分:2)
您正在使用PHP版本5.4.7,您应该已经拥有com_dotnet.dll 如果你没有它,你可以在&#34; download&#34;并添加到php目录中的ext / path。
编辑你的php.ini文件
extension=php_com_dotnet.dll
答案 2 :(得分:1)
您真正需要的是:
(您最有可能在“ C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ ...”中找到这些工具,只是使用google即可正确使用它们,非常容易)
<?php
// use this kind of name, not path to dll or whatever
// print your assemblly's full name in .NET and use that
$name = "YourAssembly, Version=1.1.1.1, Culture=neutral, PublicKeyToken=fe6263478ac";
$obj = new DOTNET($name, "YourNamespace.YourClass");
echo "success\n";
?>
是的,vaibhav对“ php.ini”是正确的。我不必编辑它。它具有正确的值(也许是默认值?)。