PHP calls C # DLL

Source: Internet
Author: User

After a long time, PHP can finally call my C # DLL.

 

Damn it, I have never known about C # com registration. I only gave the PHP part of the content in the PHP document and didn't tell me how to get the DLL.

I am still dumpily using regsvr32 to register the C # DLL.

 

Background:

Windows XP SP3; Apache 2.2.14; PHP 5.2.12;

Vs2010 Beta;

 

Language:

PhP5, C #

 

C # section:

Create a C # class library. (DLL)

After the project is created, open the properties of the project,

Click "application" (the first tab) on the left, and then click the assembly information button,

In the pop-up dialog, make assembly com-visible must be checked at the bottom!

Otherwise, the DLL cannot be accessed as COM.

(Of course, you can also write [comvisible (true)] in the class declaration in the Code. The effect is the same)

 

The Code is as follows:

 

Using system;

Using system. Collections. Generic;

Using system. LINQ;

Using system. text;

Using system. runtime. interopservices;

 

Namespace Test

{

// [Comvisible (true)] // or check "assembly com-visible" at Application-Assembly_Information dialog;

Public class phpimage

{

Public String test ()

{

Return "Hello world! ";

}

}

}

Then compiled the DLL, which is called phpimage. dll. I thought the following statement can be written directly in PHP: <? PHP $ myphpimg = new COM ("test. phpimage"); echo $ myphpimg-> test ();?>

 

 

The result is of course incorrect and the COM object cannot be created.

Actually, I want to know where the system knows which DLL test. phpimage corresponds!

 

After half a day, I found a post, drawing a gourd like a sample:

 

Http://hi.baidu.com/softways/blog/item/6c0755b515731dcb36d3cabf.html

 

He wants to: Release C # com DLL

I just want to know how to register C # com DLL.

I will repeat it again:

 

The key is regasm.exe, A. Net tool:

Http://msdn.microsoft.com/zh-cn/library/tzat5yw6 (vs.80). aspx

 

Register C # com DLL in this way:

(PS: My DLL is phpimage. dll)

(PS2: Please call this command line in the phpimage. dll folder)

 

Regasm phpimage. dll/TLB: phpimage. TLB/codebase

 

OK. You cannot worry about finding register. You will find a test in it. phpimage items include clsid. You can find the corresponding information of this CLSID, including the dll path.

 

Finally, "Hello World!" is displayed on my page! "

 

PS: Who knows how to use DOTNET to implement it? I can't even try it, dizzy.

 

The predecessors planted trees, and the future generations took advantage of the cold.

If this article is helpful to you, Thank you (Khan). I am also very happy!

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.