PHP calls the dll class library method developed by C. PHP calls C # developed dll class library method this article mainly introduces PHP calls C # developed dll class library method, including a complete and detailed DLL production steps and PHP call methods, if you need a friend, you can use PHP to call the C # developed dll class library method.
This article mainly introduces the dll class library method developed by PHP to call C #, including a complete and detailed DLL creation steps and PHP call methods. For more information, see
Sometimes, we need to use the dll class libraries written in other languages in php, such as the dll written in C #, which is called using the PHP new COM method, before calling the API, you must register the dll library and put the assembly into the global cache.
1. create a C # Class Library named HelloWorld
2. open the properties of the project, click "Application" (the first tab) on the left, and then click the Assembly Information button. in the displayed Dialog, the following Information must be checked at the bottom: make assembly COM-visible! Otherwise, the dll cannot be accessed as COM. (You can also write [ComVisible (true)] in the class declaration in the code. The effect is the same and you need to add the 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 strongly named signature file.
Open the properties of the project, click Signing on the left to check and Sign the assembly in Choose a strong name key file: Select Select the created HelloWorld. snk file
4. create a class library and compile it into a dll
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:
The code is as follows:
Regasm HelloWorld. dll <回车>
At this time, the. net assembly of this. dll will become a standard Com component, but it cannot be used yet. it must be changed to a global Com component.
Add the assembly to the global assembly cache
Enter the prompt window and enter:
The code is as follows:
Gacutil/I HelloWorld. dll <回车>
At this time, your dll will be copied to the Global Assembly Cache. that is to say, you can use this dll component no matter which hard disk on this computer.
If you do not perform a strong name signature, this step will prompt loading failure.
PHP testing:
The code is as follows:
$ R = new Com ("HelloWorld. Hello ");
$ S = $ r-> Write ();
Echo $ s;
?>
Command:
The code is as follows:
CD [/D] [drive:] [path] # enter the specified path
CD [..] # returns the parent directory
This article mainly introduces the dll class library method developed by PHP to call C #, including a complete and detailed DLL creation steps and PHP call methods. if you need it, you can...