PHP invoke VC written by COM component instance _php instance

Source: Internet
Author: User
I. Create COM components with VC
1, VC new Project-> ATL project, enter name Comtest,comtest will be the name of the COM component.


2, to the ATL Project Wizard, do not need to change, complete the wizard. After the wizard completes, VC will automatically generate a series of programs.


3. Switch to Class View, right-click on Comtest item, add Class, select ATL Simple Object,


4, come to the ATL Simple Object Wizard, enter you want to create a new class name MyClass, complete the wizard. (note, also want to fill in ProgID, some vs will automatically complement)


5, Back to Class View, in IMyClass right, add method, will go to Add Method Wizard.


6, came to Add Method Wizard, we want to achieve the calculation of the addition of 2 number of functions, such as the following, parameters A and B are [in] long,c for COM return parameters, for [out, retval] long*, is a pointer. Complete the wizard.

7, in MyClass.cpp find the method we just added, add (long A, long B, long* c), modified as follows:
Copy Code code as follows:
STDMETHODIMP Cmyclass::add (Long A, long B, long* c)
{
*c = a + b;
return S_OK;
}

8, after compiling, in the build directory to find ComTest.dll, registered to the system
Copy Code code as follows:
regsvr32 ComTest.dll

Second, PHP calls COM components

Copy Code code as follows:
<?php

$com = new COM ("Comtest.myclass") or Die ("Cannot invoke Comtest");
Echo $com->add (1, 2);

Normally, it's done here.

However, by default, the functionality of the PHP invoke COM component is not open. PHP executes the above code to report Fatal Error:class ' COM ' not found error. Modify the PHP configuration as follows:

Copy Code code as follows:

Extension=php_com_dotnet.dll

Conclusion
This feature is the function of PHP invoke COM components, although very convenient to call, development is relatively simple, but also because of the use of COM component technology, limited only windows can use.



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.