PHP calls a COM component example written in VC_PHP tutorial

WBOY
Release: 2016-07-13 10:35:08
Original
901 people have browsed it

1. Use VC to create COM components
1. Create a new project in vc -> ATL project, enter the name ComTest, ComTest will be used as the name of the COM component.


2. When you get to the ATL project wizard, no changes are needed to complete the wizard. After the wizard is completed, vc will automatically generate a series of programs.


3. Switch to the class view, right-click on the ComTest item, add a class, select ATL simple object,


4. Go to the ATL simple object wizard, enter the name of the class you want to create, MyClass, and complete the wizard. (Note, you also need to fill in the ProgID, some vs will automatically complete it)


5. Return to the class view, right-click on IMyClass, add method, and you will enter the wizard for adding methods.


6. When we come to the Add Method Wizard, we want to implement the function of calculating the addition of two numbers, as follows, the parameters a and b are both [in] Long, c is the COM return parameter, which is [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:
Copy code 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 to the system
Copy the code The code is as follows:
regsvr32 ComTest.dll

2. PHP calls COM components

Copy the code The code is as follows:

$com = new COM("ComTest.MyClass") or die("Unable to call ComTest");
echo $com->add(1, 2);

Normal situation Next, it’s done here.

But by default, the function of PHP calling COM components is not turned on. PHP will report Fatal error: Class 'COM' not found error when executing the above code. Modify the PHP configuration as follows:

Copy the code The code is as follows:

extension=php_com_dotnet.dll

Conclusion
This function is for PHP to call COM components. Although it is very convenient to call and relatively simple to develop, it is also limited to Windows machines because of the use of COM component technology.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/746863.htmlTechArticle1. Use VC to create COM components 1. Create a new project in vc - ATL project, enter the name ComTest, ComTest will be used as COM The name of the component. 2. When you reach the ATL project wizard, no changes are needed to complete the wizard. To...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template