PHP4 calls self-compiled COM components

Source: Internet
Author: User
Author: After the PHP 4 class was completed, a snake in the East tried to call JavaBean and tried to call COM. He thought it was very difficult. He wrote an ActiveDll in PHP4 using VB6 and immediately succeeded, it is much more convenient than calling javabean. The following describes my steps. The downloaded version is from www.mm4.de. I. The ActivexDll code written with VB6 is as follows: OptionExpli author: Oriental Yike
After calling JavaBean in PHP4 and trying to call COM, I thought it was very difficult. I wrote an Active Dll using VB6 and called it in PHP4 immediately, it is much more convenient than calling javabean. The following describes my steps.

The downloaded version is http://www.mm4.de /.

I. use VB6 to write Activex Dll

The code is as follows:

Option Explicit

Private MyScriptingContext As ScriptingContext

Private MyApplication As Application

Private MyRequest As Request Private MyResponse As Response

Private MyServer As Server

Private MySession As Session Public

Sub OnStartPage (PassedScriptingContext As ScriptingContext)

Set MyScriptingContext = PassedScriptingContext

Set MyApplication = MyScriptingContext. Application

Set MyRequest = MyScriptingContext. Request

Set MyResponse = MyScriptingContext. Response

Set MyServer = MyScriptingContext. Server

Set MySession = MyScriptingContext. Session

End Sub

Public Sub OnEndPage ()

Set MyScriptingContext = Nothing

Set MyApplication = Nothing

Set MyRequest = Nothing

Set MyResponse = Nothing

Set MyServer = Nothing

Set MySession = Nothing

End Sub

Public Function Test_Number (num) As Variant

If num <0 Then Get_Number_Attrib =-1

If num> 0 Then Get_Number_Attrib = 1

If num = 0 Then Get_Number_Attrib = 0

End Function

The specific method is as follows: Create a VB6 project, ActiveX Dll name the project P_test, class name c_test

Class file content as above.

Compile and generate the p_test.dll file

II. Registration

Run: regsvr32 p_test.dll

3. Compile the php file. the test. php4 code is as follows:


$ B = new COM ("p_test.c_test ");

$ A = $ B-> Test_Number (-454 );

Echo $;

?>

Running the php4 file will display-1

The possible problem is that when compiling the project

Microsoft Active Server Pages Object Library

Reference. find and modify the library for "Project-> References" and check

In contrast, PHP4 calls com better than PHP4 calls javabean, because it is a Ms system after all. You can also compile the control for calling the database by yourself and call it with PHP4. To some extent, it is the same as calling the javabean with PHP, and it can be said that the "hidden Source Code" is implemented ".

This article is from: www.phpstar.com

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.