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.