PHP calls C # developed DLL class library method, _php tutorial

Source: Internet
Author: User
Tags net command

PHP calls the DLL class library method developed by C #,


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), 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 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: <?php
$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 [..] #返回父目录


PHP calls C program

I'm here to give you a PHP how to execute a few functions of the system command, I hope to bring you help, I am Linux for example, and DOS is the same function, however, must have the permission to execute. Php

How does PHP invoke the C language program?

PHP to IS can be two or three code, you are sure that your C language will publish webservices, and generate standard SOAP files, if you think PHP is written in C language can be simple to call each other, then you are wrong, the idea is good, want to combine the merits of each other, and you that point calculation, PHP can't meet, are you sure?

http://www.bkjia.com/PHPjc/851338.html www.bkjia.com true http://www.bkjia.com/PHPjc/851338.html techarticle PHP calls C # developed DLL class library method, sometimes we need to use PHP in other languages written DLL class library, such as C # written DLL, method is to use the PHP new COM method to invoke, ...

  • Related Article

    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.