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.