PHP calls the COM component instance compiled by VC _ PHP Tutorial

Source: Internet
Author: User
PHP calls the COM component instance compiled by VC. 1. create COM component with VC 1. create project-ATL project with vc, enter the name ComTest, and ComTest will be used as the name of COM component. 2. complete the wizard without any changes to the ATL Project Wizard. Direction 1. use VC to create COM components1. create a project in vc-> ATL Project. enter the name ComTest and ComTest as the name of the COM component.


2. complete the wizard without any changes to the ATL Project Wizard. After the Wizard is complete, vc will automatically generate a series of programs.

3. switch to the class view, right-click the ComTest item, add a class, and select an ATL simple object,

4. go to the ATL simple object wizard and enter the new class name MyClass to complete the Wizard. (Note: You must enter the ProgID, and some vs will automatically complete the configuration)

5. return to the class View and right-click IMyClass to add a method. the Wizard for adding a method will be displayed.

6. in the Add method wizard, we want to calculate the sum of two numbers. for example, parameters a and B are both [in] Long, and c are the return parameters of COM, which are [out, retval] Long * is a pointer. Complete the Wizard.
7. find the method we just added in MyClass. cpp, add (LONG a, LONG B, LONG * c), and modify it as follows:

The code is as follows:

STDMETHODIMP CMyClass: add (LONG a, LONG B, LONG * c)
{
* C = a + B;
Return S_ OK;
}


8. after compilation, find ComTest. dll in the generated directory and register it with the system.

The code is as follows:

Regsvr32 ComTest. dll

II. PHP calls COM components

The code is as follows:


$ Com = new COM ("ComTest. MyClass") or die ("cannot call ComTest ");
Echo $ com-> add (1, 2 );


Under normal circumstances, it will be done here.

However, by default, PHP does not enable the function of calling the COM component. When PHP executes the above code, it will report the Fatal error: Class 'com' not found error. Modify the PHP configuration as follows:

The code is as follows:


Extension = php_com_dotnet.dll


Conclusion
This function is used by PHP to call COM components. although it is convenient to call and development is relatively simple, it is only available for Windows machines because of the use of COM component technology.



Example 1. vc creates a project-ATL project and enters the name ComTest. ComTest is used as the name of the COM component. 2. complete the wizard without any changes to the ATL Project Wizard. To...

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.