Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create C# DLL to use in PHP

Tags:

php

asp.net

I'm using a C#.NET DLL with ASP.NET 2.0 and it's working now. I want to use the same DLL in PHP.

I'm a newbie in PHP; would someone please tell me how to use it in PHP or could you share some example?

like image 718
muhammadanish Avatar asked Feb 03 '23 12:02

muhammadanish


2 Answers

PHP has a built-in Windows-only extension called DOTNET that allows you to use .NET libraries in a PHP application.

Note that you'll need to make sure your assemblies are declared as COM visible:

[assembly: ComVisible(true)]

Here are two examples.

<?php
 $stack = new DOTNET("mscorlib", "System.Collections.Stack");
 $stack->Push(".Net");
 $stack->Push("Hello ");
 echo $stack->Pop() . $stack->Pop();
?>

Another example demonstrating functionality of DOTNET class:

<?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

  }
?> 
like image 123
foxy Avatar answered Feb 05 '23 08:02

foxy


you are using the PHP Version 5.4.7 you should already have com_dotnet.dll if you dont have it you can download it on "download" and add to your ext/ path inside php directory.

Edit you php.ini file

extension=php_com_dotnet.dll
like image 24
vaibhav Avatar answered Feb 05 '23 06:02

vaibhav