DLL class library method that PHP invokes C # development

Source: Internet
Author: User

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 [..] #返回父目录

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.