Methods of using COM components in JS

Source: Internet
Author: User

First create a COM component, insert a dual interface ITest, and implement the following three methods on this interface:

STDMETHODIMP ctest::test (void)    //No input/output parameter {     //TODO: Add implementation code in this     MessageBox (null,l "test", L "test", MB_OK);      return S_OK;} STDMETHODIMP Ctest::test1 (BSTR A1)   //have a string input parameter {     //TODO: Add implementation code in this    MessageBox (null,a1,l "test", MB_OK);     return S_OK;} STDMETHODIMP Ctest::test3 (bstr* A1)  //have a bstr* output parameter {     //TODO: Add implementation code in this      MessageBox (null,l "test3", L "test ", MB_OK);     *a1=::sysallocstring (L "Beacon to million gold" in March);     return S_OK;}

The above three methods in COM demonstrate that there are no input and output parameters, one input parameter, and one output parameter of three cases. After the program is compiled, use regsvr32 to register the components in the system, and then you can use JavaScript in IE to call the COM component of the method, in two cases are dropped, the example is as follows:

1. Calling COM methods directly

Create an HTML text and enter the following:

2. Calling COM methods in JavaScript functions

Create an HTML text and enter the following:

Note that a COM component is written for other system calls, so the input-output parameter string should be a BSTR type.

3. Methods for setting properties of COM components

First set the properties in the COM component. Adding attribute variables to the interface class

BSTR M_bstr;

Right-click on the interface, select "Add"-〉 "adding Properties" in the Add Property Wizard, enter the parameter type "BSTR" in the Input property type, "property name" Input "BSTR", the wizard automatically generates the property functions Put_bstr and Get_bstr, as follows:

STDMETHODIMP Ctest::get_bstr (bstr* pVal) {//TODO: Add implementation code *PVAL=M_BSTR; return S_OK;} STDMETHODIMP CTest::p ut_bstr (BSTR newval) {//TODO: Add implementation code m_bstr=newval here; MessageBox (null,m_bstr,l "attribute Test", MB_OK); return S_OK;}

The following code demonstrates setting and getting properties in the JavaScript script of IE

  

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.