This article mainly introduces PHP to call C # Development DLL class library method, contains a complete detailed DLL production steps and PHP call method, need friends can refer to the following
Sometimes we need DLL libraries written in other languages in PHP, such as DLLs written in C #, by using the PHP new COM method to register the DLL library and put the assembly into the global cache before invoking it.
1. Create a C # Class Library, named: HelloWorld
2. Open the properties of the item, click on the left "application" (is the first tab), and then click the assembly Information button, in the pop-up dialog, must be on the bottom hook: Make assembly Com-visible! Otherwise, this DLL will not be accessible as COM. (You can also write [ComVisible (true)] in the class declaration in your code, with the same effect, you need to add a using System.Runtime.InteropServices; reference)
3. Create strong-named signature files and use
Use Vs.net's "vsitual Studio." NET Tool "-->vistual Studio. NET command prompt, the strong named signature file is created by entering Sn-k d:helloworld.snk carriage return
Open the properties of the item, click on the left signing tick sign the assembly at Choose a strong name key file: Select Select the Helloworld.snk file you just created
4. Create a class library and compile it into a DLL
Copy code code as follows:
Namespace HelloWorld
{
[ComVisible (True)]//or check "Assembly com-visible" at Application-assembly_information Dialog;
public class Hello
{
public string Write ()
{
Return to "Hello World";
}
}
}
5. Locate the DLL folder path, and then use Vs.net's vsitual Studio. NET Tool "-->vistual Studio. NET command prompt
Enter the DLL folder below:
Copy code code as follows:
regasm helloworld.dll< Carriage return >
At this point, the. NET assembly of this. dll becomes a standard COM component, but it is not available and must be made into a global COM component.
To add an assembly to the global Assembly cache
Enter the prompt window and enter:
Copy code code as follows:
gacutil/i helloworld.dll< Carriage return >
At this point, your DLL is copied into the global assembly cache. That is, you can use this DLL component on any hard drive on this computer.
If you do not make a strong-named signature, this step prompts for a failed load
PHP Test:
Copy code code as follows:
$r =new Com ("Helloworld.hello");
$s = $r->write ();
Echo $s;
?>
Command character:
Copy code code as follows:
CD [/d] [Drive:][path] #进入指定路径
CD [..] #返回父目录