PHP calls C # developed DLL class library method
This article mainly describes the PHP call C # Developed DLL class library method, including a complete detailed dll making steps and PHP call method, the need for friends can refer to the following
Sometimes we need to make use of DLL class libraries written in other languages in PHP, such as DLLs written in C #, by invoking the PHP new COM method, registering the DLL library and putting the assembly into the global cache before calling.
1. Create a C # Class Library named: HelloWorld
2. Open the project's properties, click on the left "application" (that is, the first tab), 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 in COM mode. (You can also write [ComVisible (true)] in the class declaration in your code, as an effect, you need to increase the using System.Runtime.InteropServices; reference)
3. Create a strong-named signature file and use
Use Vs.net's "vsitual Studio. NET Tools "-->vistual Studio. NET command prompt, enter sn-k d:\HelloWorld.snk return to create a strong-named signature file
Open the project's properties, click on the left signing sign the assembly in 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 the 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 "Hello World";
}
}
}
5. Locate the DLL folder path, and then use the Vs.net "Vsitual Studio. NET Tools "-->vistual Studio. NET command prompt
Enter the DLL folder by entering:
Copy the code code as follows:
RegAsm HelloWorld.dll <回车>
At this point, the. NET assembly of this. dll becomes a standard COM component, but it is not yet available and must be turned into a global COM component.
Add an assembly to the global Assembly cache
Enter the prompt window and enter:
Copy the code code as follows:
gacutil/i HelloWorld.dll <回车>
At this point, your DLL is copied to the global assembly cache. That is, you can use this DLL component on any hard disk on this computer.
If you do not make a strong-named signature, this step will prompt the load to fail
PHP Test:
Copy the code code as follows:
$r =new Com ("Helloworld.hello");
$s = $r->write ();
Echo $s;
?>
Under the command symbol:
Copy the code code as follows:
CD [/d] [Drive:][path] #进入指定路径
CD [..] #返回父目录
http://www.bkjia.com/PHPjc/852822.html www.bkjia.com true http://www.bkjia.com/PHPjc/852822.html techarticle PHP calls C # developed DLL class library method this article mainly introduces the PHP call C # Developed DLL class library method, contains a complete detailed dll making steps and PHP call method, need friends can ...