_php instance of COM component instance written by PHP call VC

Source: Internet
Author: User
First, create COM components with VC1, VC new Project, ATL project, enter the 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 is completed, the VC will automatically generate a series of programs.

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

4. Come to the ATL Simple Object Wizard, enter the class name you want to create MyClass, and complete the wizard. (note, also fill in the ProgID, some vs will be auto-complete)

5, return to the Class View, in the IMyClass right-click, add method, will go to Add Method Wizard.

6, come to Add Method Wizard, we want to implement the function of calculating the addition of 2 numbers, as follows, the 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 CodeThe code is as follows: Stdmethodimp Cmyclass::add (Long A, long B, long* c)
{
*c = a + b;
return S_OK;
}
8. After compiling, find ComTest.dll in the build directory, register to System
Copy CodeThe code is as follows: regsvr32 ComTest.dll

Second, PHP calls COM components
Copy the Code code as follows:
$com = new COM ("Comtest.myclass") or Die ("Cannot call comtest");
Echo $com->add (1, 2);
Under normal circumstances, it is done here.

However, by default, the functionality of the PHP call COM component is not open. PHP execution of the above code will be reported Fatal Error:class ' COM ' not found error. Modify the PHP configuration as follows:
Copy the Code code as follows:
Extension=php_com_dotnet.dll
Conclusion
This feature is a function of PHP calls COM components, although very convenient to call, development is relatively simple, but also because the use of COM component technology, only Windows-only machine can be used.



  • 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.