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.