PHP calls the dll class library method developed by C#, _PHP tutorial

WBOY
Release: 2016-07-13 10:22:05
Original
926 people have browsed it

PHP calls the dll class library method developed in C#,

Sometimes, we need to use dll libraries written in other languages ​​in php, such as dlls written in C#. The method is to use the PHP new COM method to call. Before calling, the dll library must be registered and the program Set into the global cache.

1. Create a C# Class Library and name it: HelloWorld
2. Open the properties of the project , click "Application" on the left (the first tab), and then click the Assembly Information button. In the pop-up Dialog, you must check the bottom box: Make assembly COM -visible! Otherwise, this dll will not be accessible in COM mode. (You can also write [ComVisible(true)] in the class declaration in the code, the effect is the same, you need to add using System.Runtime.InteropServices; reference)

3. Create a strongly named signature file and use
Use vs.net’s “Vsitual Studio .Net Tool” -->Vistual Studio .Net command prompt, enter sn -k d:HelloWorld.snk and press Enter to create a strong named signature file
Open the properties of the project, click Signing on the left and check Sign the assembly. Select at Choose a strong name key file: and select the HelloWorld.snk file you just created

4. Create a class library and compile it into a dll

Copy code The code is as follows:
namespace HelloWorld
{
//[ComVisible(true)] //or check "Assembly COM-Visible" at Application-Assembly_Information dialog ;
Public class Hello

Public string Write()
                                                                                                   return "Hello World";                                                                                                                                                  }  
}


5. Find the dll folder path
, and then use vs.net’s “Vsitual Studio .Net Tool” -->Vistual Studio .Net Command Prompt
Enter the dll folder and enter:

Copy code
The code is as follows:regasm HelloWorld.dll
At this time, the .net assembly of this .dll becomes a standard Com component, but it cannot be used yet. It must be turned into a global Com component.
Add the assembly to the global assembly cache Enter the prompt window and enter:




Copy code

The code is as follows:gacutil /I HelloWorld.dll
At this time, your dll will be copied to the global assembly cache. In other words, this dll component can be used no matter which hard drive is on this computer.
If strong naming signature is not performed, this step will prompt a loading failure


PHP test:


Copy code

The code is as follows: $r=new Com("HelloWorld.Hello");
$s=$r->Write();
echo $s;
?>

Command line:


Copy code
The code is as follows:CD [/D] [drive:][path] #Enter the specified path CD [..] #Return to parent directory

php calls c program

Here I will give you a few functions on how to execute system commands in PHP. I hope it can help you. I am using Linux as an example. They are the same functions as DOS. However, you must have execution permissions. php


How to call C language program in php?

PHP can be done with two or three lines of code. Are you sure that your C language can publish webservices and generate standard soap files? If you think that PHP is written in C language and can simply call each other, then you are wrong. Yes, the idea is good. I want to combine the advantages of each. In addition, PHP cannot satisfy your calculation. Are you sure?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/851338.htmlTechArticlePHP calls the dll class library method developed in C#. Sometimes, we need to use other languages ​​​​to write in php dll class library, such as dll written in C#, the method is to use the PHP new COM method to call...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template