Compile COM components in VC to provide PHP calls

Source: Internet
Author: User
Recently, the project requires PHP to parse binary data. if it is more difficult to directly use PHP, you need to compile the COM component in VC to provide PHP calls. This article introduces how to compile the COM component in VC to provide a PHP call to calculate the addition of two numbers. Use VC to create COM components 1. vc to create a project-& gt; recently, the project requires PHP to parse binary data. if it is more difficult to directly use PHP, you need to compile the COM component in VC, PHP call is provided. This article introduces how to compile the COM component in VC to provide a PHP call to calculate the addition of two numbers. Use VC to create COM component 1. vc to create a project-> ATL project, enter the name ComTest, and ComTest will be used as the name of the COM component.


2. complete the wizard without any changes to the ATL Project Wizard. After the Wizard is complete, vc will automatically generate a series of programs.

3. switch to the class view, right-click the ComTest item, add a class, and select an ATL simple object,

4. go to the ATL simple object wizard and enter the new class name MyClass to complete the Wizard. (Note: You must enter the ProgID, and some vs will automatically complete the configuration)

5. return to the class View and right-click IMyClass to add a method. the Wizard for adding a method will be displayed.

6. in the Add method wizard, we want to calculate the sum of two numbers. for example, parameters a and B are both [in] Long, and c are the return parameters of COM, which are [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:
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 with the system.
regsvr32 ComTest.dll
PHP calls COM components
 Add (1, 2 );
Under normal circumstances, it will be done here.
However, by default, PHP does not enable the function of calling the COM component. When PHP executes the above code, it will report the Fatal error: Class 'com' not found error. Modify the PHP configuration as follows:
extension=php_com_dotnet.dll
Conclusion This function is used by PHP to call COM components. although it is convenient to call and development is relatively simple, it is only available for Windows machines because of the use of COM component technology.
Reference http://blog.csdn.net/mycwq/article/details/22417961

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.