Simple implementation of com components in javascript, javascript Components

Source: Internet
Author: User

Simple implementation of com components in javascript, javascript Components

First, create a COM component and insert a dual-interface Itest, which implements the following three methods:

STDMETHODIMP Ctest: test (void) // no input/output parameter {// TODO: add the implementation code MessageBox (NULL, L "test", L "test", MB_ OK) here ); return S_ OK;} STDMETHODIMP Ctest: test1 (BSTR a1) // There is a string input parameter {// TODO: add the implementation code MessageBox (NULL, a1, L "test ", MB_ OK); return S_ OK;} STDMETHODIMP Ctest: test3 (BSTR * a1) // There Is A BSTR * output parameter {// TODO: add the implementation code MessageBox (NULL, L "test3", L "test", MB_ OK); * a1 =: SysAllocString (L "March "); return S_ OK ;}

The preceding three methods in COM demonstrate three situations: no input/output parameters, one input parameter, and one output parameter. After the program is compiled, register the component with regsvr32 in the system, and then you can use javascript to call the com component method in IE. The following is an example:

1. directly call the com Method

Create an html text and enter the following content:

<Html> 

2. Call the com method in javascript Functions

Create an html text and enter the following content:

<Html> 

Note that the com component is used by other systems. Therefore, the input/output parameter string must be of the BSTR type.

3. How to Set attributes of com components

First, Set Properties in the com component. Add property variables to the interface class

BSTR m_bstr;

Right-click the interface and choose "Add now"> "add property". In the "add property" Wizard, enter the parameter type "BSTR" in "Enter property type ", enter "bstr" in "attribute name". The wizard automatically generates the put_bstr and get_bstr attributes, as shown below:

STDMETHODIMP Ctest: get_bstr (BSTR * pVal) {// TODO: add the implementation code * pVal = m_bstr; return S_ OK;} STDMETHODIMP Ctest: put_bstr (BSTR newVal) {// TODO: add the implementation code m_bstr = newVal; MessageBox (NULL, m_bstr, L "Property Test", MB_ OK); return S_ OK ;}

The following code demonstrates setting and obtaining attributes in javascript scripts of IE.

<Html> 

The simple implementation method of using the com component in javascript above is all the content shared by the editor. I hope to give you a reference, and I hope you can provide more support for the customer's house.

Related Article

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.